zoukankan      html  css  js  c++  java
  • UVa11609

    11609 Teams
    In a galaxy far far away there is an ancient game played among the planets. The specialty of the game
    is that there is no limitation on the number of players in each team, as long as there is a captain in
    the team. (The game is totally strategic, so sometimes less player increases the chance to win). So the
    coaches who have a total of N players to play, selects K (1  K  N) players and make one of them
    as the captain for each phase of the game. Your task is simple, just find in how many ways a coach
    can select a team from his N players. Remember that, teams with same players but having different
    captain are considered as different team.
    Input
    The first line of input contains the number of test cases T  500. Then each of the next T lines contains
    the value of N (1  N  109), the number of players the coach has.
    Output
    For each line of input output the case number, then the number of ways teams can be selected. You
    should output the result modulo 1000000007.
    For exact formatting, see the sample input and output.
    Sample Input
    3123
    Sample Output
    Case #1: 1
    Case #2: 4
    Case #3: 12

    题意:
           有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案。

    分析:
           不论谁当队长,情况都是等价的。假设第一个人当队长,剩下的n-1个人可选可不选,有2^(n-1)种选法,所以答案就是n*2^(n-1)。

     1 #include <cstdio>
     2 #include <cmath>
     3 #define LL long long
     4 const LL MOD = 1000000007;
     5 LL pow_mod(LL a,LL p,LL n){
     6     if(p == 0) return 1;
     7     LL ans = pow_mod(a,p / 2,n);
     8     ans = ans * ans % n;
     9     if(p % 2 == 1) ans = ans * a % n;
    10     return ans;
    11 }
    12 int main(){
    13     int T; scanf("%d",&T); int kase = 0;
    14     while(T--){
    15         int n; scanf("%d",&n);
    16         printf("Case #%d: %lld
    ",++kase,n * pow_mod(2,n - 1,MOD) % MOD);
    17     }
    18     return 0;
    19 }
    View Code
  • 相关阅读:
    VS2015编译OpenSSL1.0.2源码
    VS2015编译CURL7.54.0源码
    Mac OS Yosemite 文件批量重命名
    https 原理
    把本地仓库导入到Github
    jquery cdn加速注意事项
    关于CSS 里的_width是什么意思???
    HTML的footer置于页面最底部的方法
    html-include
    GitHub Permission to <<repository>> denied to <<username>>
  • 原文地址:https://www.cnblogs.com/cyb123456/p/5850840.html
Copyright © 2011-2022 走看看