ZCMU—1568

来源:互联网 发布:java的分支 编辑:程序博客网 时间:2024/06/16 07:26

1568: Climbing Stairs

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 30  Solved: 12
[Submit][Status][Web Board]

Description

There is a ritual that some monks of Byteland perform every century as a sign of respect and worship towards BOOL, the God of Byteland.

All the monks train for many years in order to accomplish an extremely hard task, that is the one of accessing the sacred temple of Byteland, where only the best of the bests monks are allowed to enter and worship their god, BOOL.

The training the monks perform, usually consists of several physically and intellectually challenging tasks, trained and perfected over the course of many years, so that one of them can be eligible for the ultimate task that is a combination of both physical effort as well as mental effort.

This final task is the actual possibility of trying to access the sacred temple of Byteland, that is located on the top of a very high mountain, where reckless storms and heavy rains usually occur.

The access to this mountain is done by climbing an enourmous set of stairs that spiral around the mountain until it ends on the top of the mountain where the sacred temple door is located.

The door can only be opened by unlocking it. To unlock the door, the monk only sees a hole in it, a lever, and he also spots a very large amount of little round stones on the ground, and he understands that the only way to open the door is to place an exact pre-determined amount of stones trough that hole, so that when the number is correct, he will push the lever down, and the door will open. If this number is incorrect, the lever will be locked by the incorrect stones and a whole new century must pass so that the storms can erode the stones and a new monk can be selected for the task.

This year, YOU were the one selected to climb the huge set of stairs, and you are extremely well prepared... You have done your training very well and you are also aware of two very important facts that will be key for your success... The favourite number base on Byteland is base 2, and Gods favourite number is the largest number on this base. You also know that the number of stones you need to place on the door hole is related to the way everyone climbs the stairs and with the number of stairs itself.

As the monks take several supplies for the demanding trip, they can only climb either one or two steps at a time. You understood that the number of stones you need to place on the door is closely related with the way you climb the stairs. Suppose the number of stairs you need to climb is N. Also, let the number of ways you have of climbing those N stairs be M. Now, the number of stones required is equal to the number of 1's in the base-2 representation of (M modulo 1000000007).

You won't fail, as you are extremely well ready, but you have made everyone on your town extremely excited with your journey, so, given the number N of steps you are to climb and a guess, G, from the people of your village, you need to see if they are correct or not.

More formally, given a number N of steps to climb and a guess G from your village, you need to check if guess G is accordingly to your correct calculations. They are correct if you manage to enter the temple using their guess, or incorrect otherwise. You should output the string “CORRECT” if they are correct, or “INCORRECT” if they are incorrect. (Quotes for clarity only). Please read the section "Output Explanation" for some clarification on the example cases.

Input

The first line of each official test case file will contain an integer T, that stands for the number of test cases on that specific test case file.
The next T lines contain two-space separated integers, N and G, respectively, the number of steps the monk needs to climb and the guess from the village's population.

Constraints

In each file, ≤ 100000, i.e., each file will contain 100000 test cases (this value needs to be read from standard input).

1 ≤ N ≤ 1000000

0 ≤ G ≤ 50

Output

Output will contain the string "CORRECT" or "INCORRECT" on a single line, as explained above on the problem statement.

Sample Input

2
1 1
7 4

Sample Output

CORRECT
INCORRECT

【分析】

读题难的题目....题意就是问你斐波那契数列第i个的二进制上的1的个数是不是G个...
预处理一下斐波那契数列直接check...
【代码】
#include<stdio.h>#define MOD 1000000007int f[1000100];int check(int x){    int ans=0;    while(x)    {        ans+=x%2;        x/=2;    }    return ans;}int main(){f[0]=f[1]=1;    for(int i=2;i<=1000000;i++) f[i]=(f[i-1]+f[i-2])%MOD;    int T_T;    scanf("%d",&T_T);    while(T_T--)    {        int n,m;scanf("%d%d",&n,&m);        if (check(f[n])==m)    puts("CORRECT");    else puts("INCORRECT");}    return 0;}


原创粉丝点击