CodeForces 82A Double Cola

郑衡
2023-12-01

题目非常容易懂;

大爆炸五个主角Sheldon, Leonard, Penny, Rajesh and Howard排队去喝 分裂汽水 。每个人喝完之后就会分裂成两个人,从队首回到队尾。这样进行。

问第n个喝汽水的人是谁。

第一感觉,嗯,双端队列。再一看数据规模,果断死了。

然后就看出来这实际上就是个等比数列。。。因为每一段的人物相对顺序是一定的,所以实际上是判断给出的数n在这个数列的什么位置。

这个数列就是这样的:1,1,1,1,1 / 2,2,2,2,2/ 4,4,4,4,4...再就不必说啦~很简单的

Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.

For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.

Write a program that will print the name of a man who will drink the n-th can.

Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.

Input

The input data consist of a single integer n (1 ≤ n ≤ 109).

It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.

Output

Print the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.

Sample test(s)
Input
1
Output
Sheldon
Input
6
Output
Sheldon
Input
1802
Output
Penny



代码

#include <iostream>
using namespace std;
int counter;
int sum(int counter){
    int m=5,ma=1;
    for(int i=0;i<counter;i++){
        ma=ma*2;
        m=m+5*ma;
    }
    return m;
}
int xn(int counter){
    int y=1;
    for(int i=0;i<counter;++i){
        y=y*2;
    }
    return y;
}
int main()
{
    int n;
    cin>>n;
    int x=5,y=1,res=0;
    if(n<6){
        res=n;
    }
    else
    {
        counter=0;
        while(n>sum(counter)){
            counter++;
        }
        counter=counter-1;
        n=n-sum(counter);
        res=(n-1)/xn(counter+1)+1;

    }
    if(res==1) cout<<"Sheldon"<<endl;
    if(res==2) cout<<"Leonard"<<endl;
    if(res==3) cout<<"Penny"<<endl;
    if(res==4) cout<<"Rajesh"<<endl;
    if(res==5) cout<<"Howard"<<endl;
    return 0;
}


 类似资料:

相关阅读

相关文章

相关问答