zoukankan      html  css  js  c++  java
  • B

    Problem description

    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
    解题思路:简单找规律。
    结论更正一下:于是当t%s!=0时,index=t/s+1。
    AC代码:
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const string obj[5]={"Sheldon","Leonard","Penny","Rajesh","Howard"};
     4 int main(){
     5     int m,n,t,s,index;cin>>n;
     6     m=log(n/5.0+1.0)/log(2.0);//换底公式
     7     t=(n-5*((s=pow(2,m))-1));
     8     if(n>5){
     9         if(t%s)index=t/s+1;
    10         else index=t/s;
    11     }
    12     else index=n;
    13     cout<<obj[index-1]<<endl;
    14     return 0;
    15 }
  • 相关阅读:
    CF920E 补图强连通分量 BFS+set维护
    hdoj5876 补图最短路 BFS+set维护还可以更新的点.
    LA4287 tarjan求强连通分量+缩点
    cf920F SUM and REPLACE 树状数组+set 维护
    cf920G List Of Integers 二分+容斥
    cf 919D substring
    2017寒假概率dp训练题
    O(n)求数组中第k大的元素——堆排序
    O(n)求数组中第k大的元素——快排划分
    Turtlebot3入门手册之八:Realsense r200安装与测试
  • 原文地址:https://www.cnblogs.com/acgoto/p/9192008.html
Copyright © 2011-2022 走看看