Just Skip The Problem(HDU-6600)
Problem Description
Y_UME has just found a number x in his right pocket. The number is a non-negative integer ranging from 0 to 2n−1 inclusively. You want to know the exact value of this number. Y_UME has super power, and he can answer several questions at the same time. You can ask him as many questions as you want. But you must ask all questions simultaneously. In the i-th question, you give him an integer yi ranging from 0 to 2n−1 inclusively, and he will answer you if x&yi equals to yi or not. Note that each question you ask has a index number. Namely, the questions are ordered in certain aspect. Note that Y_UME answer all questions at the same time, which implies that you could not make any decision on the remaining questions you could ask according to some results of some of the questions.
You want to get the exact value of x and then minimize the number of questions you will ask. How many different methods may you use with only minimum number of questions to get the exact value of x? You should output the number of methods modulo 106+3.
Two methods differ if and only if they have different number of questions or there exsits some i satisfying that the i-th question of the first method is not equal to the i-th of the second one.Input
There are multiple test cases.
Each case starts with a line containing one positive integer n(n≤109).Output
For each test case, output one line containing an integer denoting the answer.
Sample Input
2
Sample Output
2
题意:给出一个数 n,现在有一个数 x 在 [0,2^n-1] 的范围内,可以同时给出很多数字 y 来进行询问,看是否符合 x&y=y,问有多少种方法
思路:对于给出的 n,从二进制的角度来看就是看每一位上是否有 1,以 5 为例,其二进制形式为 101,因此只需要知道其有 2 位 1,其余位是 0,即可判断 5 存在
对于本题来说,只需要找出所有单独的具有 1 其余全是 0 的数字的全排列即可,即寻找 1、2、4、8、16 ....,故而答案实质是求 1~n 的阶乘然后取模
此外,可以发现,当 n>=mod 时,直接输出 0 即可
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL quickModPow(LL a,LL b,LL mod){ LL res=1; a=a%mod; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1;} return res; }
LL getInv(LL a,LL mod){ return quickModPow(a,mod-2,mod); }
LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); }
LL LCM(LL x,LL y){ return x/GCD(x,y)*y; }
const double EPS = 1E-10;
const int MOD = 1E6+3;
const int N = 1000000+5;
const int dx[] = {-1,1,0,0,1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n>=MOD)
printf("0\n");
else{
LL sum=1;
for(int i=1;i<=n;i++)
sum=(sum*i)%MOD;
printf("%lld\n",sum);
}
}
return 0;
}

浙公网安备 33010602011771号