UVA11556 Best Compression Ever【位运算】

Being educated in Computer Science and Mathematics is not always easy. Especially not if you have “friends” who repeatedly insist on showing you their new “proofs” that P equals NP, that the Riemann
Hypothesis is true, and so on.
    One of your friends recently claims to have found a fantastic new compression algorithm. As an example of its amazing performance, your friend has told you that every file in your precious collection of random bit strings after compression would be at most b bits long! Naturally, you find this a bit hard to believe, so you want to determine whether it is even theoretically possible for this to be true.
    Your collection of random bit strings consists of N files, no two of which are identical, and each of which is exactly 1000 bits long.
在这里插入图片描述
Input
The input file contains several test cases, each of them as described below.
    The input consists of two integers N (1 ≤ N ≤ 10^15) and b (0 ≤ b ≤ 50), giving the number of files in your collection and the maximum number of bits a compressed file is allowed to have.
Output
For each test case, write to the output a line containing either “yes” if it is possible to compress all the N files in your collection into files of size at most b bits, or “no” otherwise.
Sample Input
13 3
1 0
31415926535897 40
Sample Output
yes
yes
no

问题链接UVA11556 Best Compression Ever
问题简述:(略)
问题分析
    n个文件,用b+1位是否可以表示?(全0不能表示)。使用位运算实现。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11556 Best Compression Ever */

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
    LL n;
    int bits;
    while(scanf("%lld%d", &n, &bits) != EOF)
        printf("%s\n", n <= (1LL << (bits + 1)) - 1 ? "yes" : "no");

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10358616.html
今日推荐