codeforces 82/A
来源:互联网 发布:珠海java编程培训 编辑:程序博客网 时间:2024/05/16 09:04
http://codeforces.com/problemset/problem/82/A
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.
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.
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.
1
Sheldon
6
Sheldon
1802
Penny
中间用到了等比数列的前n项和的求法。
#include <string.h>#include <stdio.h>#include <cmath>#include <iostream>using namespace std;int main(){ int n,i,m,s,t; while(~scanf("%d",&n)) { for(i=0;; i++) { if(n>5*((1<<i)-1) && n<=5*((1<<(i+1))-1)) break; } if(i>0) { m = n - 5*((1<<i)-1); s=2<<(i-1); if(m<=s) t=1; else if(m<=2*s) t=2; else if(m<=3*s) t=3; else if(m<=4*s) t=4; else t=5; } else { t=n; } if(t==1) printf("Sheldon\n"); else if(t==2) printf("Leonard\n"); else if(t==3) printf("Penny\n"); else if(t==4) printf("Rajesh\n"); else printf("Howard\n"); } return 0;}
- codeforces 82/A
- CodeForces 82A Double Cola
- CodeForces-82A-Double Cola
- CodeForces-a
- Codeforces 903A A
- Problem--82A--Codeforces--Double Cola
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- codeforces#99 a
- codeforces 105 div2 A
- codeforces #121 A
- 第三周作业——冒泡排序
- cocos2d-x控件使用CCControlButton<代码演示>
- UVa--12289 One-Two-Three
- [Android布局]在程序中设置android:gravity 和 android:layout_Gravity属性
- 一个让你迅速理解Javabean的实例
- codeforces 82/A
- Java线程总结(3):线程通信
- 【code】java_方法执行sql返回一个key
- 利用ENVI软件计算NDVI常见错误经验总结
- LeetCode:Climbing Stairs
- Bmob的一些事儿(一)
- mysql_基本数据类型
- 利用GetTickCount 函数计算某个过程执行的时间
- C/C++ 回调