1.题目描写叙述:点击打开链接

2.解题思路:本题是一道找规律的数学题,通过题意描写叙述不难知道,相当于有5棵二叉树构成了一个森林,须要你按层次遍历找到第n个人是谁。

观察后不难发现,如果最開始的一层为第0层,序号n所在层为l,那么0~l-1层之间有5*(2^l-1)个结点,令5*(2^l-1)=n,计算得。l=log(n/5+1)/log(2)。

因为第l-1层最后一个人的序号是ed=5*(2^l-1),第l层每一个人有2^l个,设k每一个人的序号(从0開始),则k=(n-ed-1)/(2^l)。事先用一个数组保存全部人的姓名。

3.代码:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std; typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair <int, int> P; char*names[]={"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; int main()
{
int n;
while(~scanf("%d",&n))
{
int l=log(((n-1)/5)+1)/log(2);//计算第n个人的层。注意用n-1整除5
int ed=5*((1<<l)-1);//计算第l-1层最后一个人的序号
int k=(n-ed-1)/(1<<l);获得第k个人的序号(从0開始。最大是4)
puts(names[k]);输出第k个人姓名
}
return 0;
}

Yandex.Algorithm 2011 A. Double Cola的更多相关文章

  1. codeforces水题100道 第六题 Yandex.Algorithm 2011 Qualification 2 A. Double Cola (math)

    题目链接:www.codeforces.com/problemset/problem/82/A题意:五个人排队喝可乐,一个人喝完一杯,就在可乐的最后面放两杯自己喝的可乐,问第n个喝的人是谁.C++代码 ...

  2. CodeForces 86D(Yandex.Algorithm 2011 Round 2)

    思路:莫队算法,离线操作,将所有询问的左端点进行分块(分成sqrt(n) 块每块sqrt(n)个),用左端点的块号进行排序小的在前,块号相等的,右端点小的在前面. 这样要是两个相邻的查询在同一块内左端 ...

  3. Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树

    题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...

  4. Yandex.Algorithm 2011 Round 2 D. Powerful array 莫队

    题目链接:点击传送 D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input ...

  5. Yandex.Algorithm 2018, final round

    Yandex.Algorithm 2018, final round A Smart Vending B LIS vs. LDS C Eat And Walk D Search Engine E Gu ...

  6. 快速切题CF 158B taxi 构造 && 82A double cola 数学观察 难度:0

    实在太冷了今天 taxi :错误原因1 忽略了 1 1 1 1 和 1 2 1 这种情况,直接认为最多两组一车了 2 语句顺序错 double cola: 忘了减去n的序号1,即n-- B. Taxi ...

  7. B - Double Cola

    Problem description Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double C ...

  8. codeforcess水题100道

    之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型, ...

  9. BZOJ4614 [Wf2016]Oil

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

随机推荐

  1. BestCoder 2nd Anniversary的前两题

    Oracle Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Su ...

  2. Cookie和Session在Node.JS中的实践(三)

    Cookie和Session在Node.JS中的实践(三) 前面作者写的COOKIE篇.SESSION篇,算是已经比较详细的说明了两者间的区别.机制.联系了.阅读时间可能稍长,因为作者本身作图也做了不 ...

  3. Visio对象插入Word后周围空白过大

    如图,空白很大,因为我在设计里选择纸张适应绘图,后发现直接复制粘贴到word就好了,没空白了.

  4. xcode 6 exporting ipa 提示 Your account already has a valid iOS distribution certificate 的另一种解决方法

    背景: 1. XCode 6.1 2. 证书:develop 证书 3. Scheme 为Device 操作: 在Product - Archive 包过程中,选择Save for Ad hoc De ...

  5. form表单提交之前判断

    1.使用onsubmit方法 <form name="Form" action="t" method="post" onsubmit= ...

  6. eclipse和maven创建WebApp项目

    Eclipse+Maven创建webapp项目<一> 1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显 ...

  7. 无法通过windows installer服务安装此安装程序包。您必须安装带有更新版本windows Installer服务的Windows

    无法通过windows installer服务安装此安装程序包.您必须安装带有更新版本windows installer服务的Windows 出现这个问题不让安装程序,可以到微软网站更新Windows ...

  8. Hash history cannot PUSH the same path; a new entry will not be added to the history stack

    这个是reactr-router的一个提示,当前路由下的history不能push相同的路径.只有开发环境存在,生产环境不存在,目前还没看到官方有去掉的意思.看不惯的话可以采取一些方法关掉这个提示.具 ...

  9. DotnetBrowser高级教程-(4)使用MVC框架4-过滤器

    dotnetbrowser内置了过滤器,所谓过滤器,就是实现了Action前后拦截,请看下例: 1.增加目录Filters,在该目录下增加新的过滤器PerformanceFilter,代码如下: pu ...

  10. 关于VS下的应用程序出现0xc000007b的问题以及OpenCV相关的0xc000007b问题

    本文参考过其他一些文章: http://www.cnblogs.com/csuftzzk/p/windows_launch_error_0xc000007b.html 这个问题在网上一查一大堆,主要的 ...