hdu 4349 Gold miner

Gold miner

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Homelesser likes playing Gold miners in class. He has to pay much attention to the teacher to avoid being noticed. So he always lose the game. After losing many times, he wants your help.

To make it easy, the gold becomes a point (with the area of 0). You are given each gold's position, the time spent to get this gold, and the value of this gold. Maybe some pieces of gold are co-line, you can only get these pieces in order. You can assume it can turn to any direction immediately.
Please help Homelesser get the maximum value.
 

 

Input
There are multiple cases.
In each case, the first line contains two integers N (the number of pieces of gold), T (the total time). (0<N≤200, 0≤T≤40000)
In each of the next N lines, there four integers x, y (the position of the gold), t (the time to get this gold), v (the value of this gold). (0≤|x|≤200, 0<y≤200,0<t≤200, 0≤v≤200)
 

 

Output
Print the case number and the maximum value for each test case.
 

 

Sample Input
3 10 1 1 1 1 2 2 2 2 1 3 15 9 3 10 1 1 13 1 2 2 2 2 1 3 4 7
 

 

Sample Output
Case 1: 3 Case 2: 7

AC代码:

C(n,0),C(n,1),C(n,2)...C(n,n).当中有多少个奇数。
 
就是统计N表示成二进制有多少个1,然后就是就是2^cnt。
 
复制代码
#include<stdio.h>
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int cnt=0;
        while(n>0)//十进制转化为二进制
        {
            if(n%2==1)++cnt;
            n>>=1;
        }
        printf("%d\n",1<<cnt);//1<<cnt
    }
    return 0;
}

//假如让求有多少个偶数此时为 n+1-(1<<cnt);

链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?cid=402&pid=1003

计录N表示成二进制有多少个1

void binary( int n)
{
  int c;//计录N表示成二进制有多少个1
  for( c=0;n;c++)
   n&=(n-1);//消除最低位的1
  
}
// 此算法时间复杂度只与c有关与n无关

 

posted @ 2012-08-07 16:48  jiai  Views(145)  Comments(0Edit  收藏  举报