Just Skip The Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 843 Accepted Submission(s): 462
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,对方心里想一个数,范围是,然后你可以提问无数个问题,去确定对方心里想的数,然后输入的数,是代表n,输出的数,是代表在最少问题的情况下,有多少种提问的方法;
首先,其实这题意还是需要解释一下:
- 你提的“问题”:你自己想一个数(Y),然后提问的问题就是这个数字,然后对方会用他心里的数字(X),去跟你这个数字进行 与操作(&)然后回答你操作完成以后,结果是不是你这个数字; 也就是 : X&Y?=Y,对方只会回答是否,所以你需要自己去确定他的数;
- 样例中给了2,然后对方的数可能是0,1,10,11;然后可以考虑一下,其实提问的问题,可以是01和10,与操作的答案可以确定出未知数的两位到底是什么,所以可以得出,问题最少的数量是n,也就是问题可以是01,10,100,1000,10000....那么输出为何是2呢,也就是因为提问问题的顺序不同,即为不同结果,所以结果应该是n的全排列个数,也就是n!;
- 其实问题上还有一个点,就是结果要对1e6+3进行取模,所以当n大于这个数时,n!里面会包括1e6+3,所以取余结果应该是0,所以只需要进行对1e6+3之前的数打表存起来,然后之后的数结果都是0,输出即可
代码篇:
#include <iostream>
#define mod 1000003
#define ll long long
using namespace std;
ll ans, n, a[1000020];
int main()
{
ios::sync_with_stdio(false);
a[1] = 1;
for(int j = 2; j <= 1000002; j++) ///打表
{
a[j] = a[j - 1] * j % mod;
}
while(cin >> n)
{
if(n >= 1000003) ///1000003之后的结果为0
cout << 0 << endl;
else
cout << a[n] << endl;
}
return 0;
}
OVER!