zcmu-2269: Double Cola(找规律)

探讨了在特定购买和复制行为下,队列中人物的变化规律及算法实现。通过数学归纳法,分析了队列中每个人物重复次数的增长模式,并提供了一种高效算法来确定第n次购买者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考博主链接 感谢!

2269: Double Cola

Time Limit: 2 Sec  Memory Limit: 256 MB
Submit: 34  Solved: 26
[Submit][Status][Web Board]

Description

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples

Input

1

Output

Sheldon

Input

6

Output

Sheldon

Input

1802

Output

Penny

 

找下规律可以发现队伍改变是有规律的,用abcde代表5个人:

队伍变化:abcde -> aabbccddee -> aaaabbbcccdddeee -> aaaaaaaabbbbbbbbccccccccddddddddeeeeeeee ...

单个人的人数变化:1 -> 2-> 4 -> 8 ...(each_cnt每次都*2)

队伍总人数变化:5个 -> 10个 -> 20个 -> 40个(sum也是每次都*2)

如果没整明白的话可以自己带个数进去算一下

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char nm[10][10] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard" };
int main()
{
    int n,sum = 5,each_cnt = 1,res;
    scanf("%d",&n);
    while(n > sum)
    {
        n -= sum;
        each_cnt *= 2;
        sum *= 2;
    }
    if(n % each_cnt == 0)   res = n / each_cnt;
    else    res = n / each_cnt + 1;
    switch(res)
    {
        case 1:puts(nm[0]);break;
        case 2:puts(nm[1]);break;
        case 3:puts(nm[2]);break;
        case 4:puts(nm[3]);break;
        case 5:puts(nm[4]);break;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值