Yandex.Algorithm 2011 A. Double Cola
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的更多相关文章
- codeforces水题100道 第六题 Yandex.Algorithm 2011 Qualification 2 A. Double Cola (math)
题目链接:www.codeforces.com/problemset/problem/82/A题意:五个人排队喝可乐,一个人喝完一杯,就在可乐的最后面放两杯自己喝的可乐,问第n个喝的人是谁.C++代码 ...
- CodeForces 86D(Yandex.Algorithm 2011 Round 2)
思路:莫队算法,离线操作,将所有询问的左端点进行分块(分成sqrt(n) 块每块sqrt(n)个),用左端点的块号进行排序小的在前,块号相等的,右端点小的在前面. 这样要是两个相邻的查询在同一块内左端 ...
- Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树
题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...
- Yandex.Algorithm 2011 Round 2 D. Powerful array 莫队
题目链接:点击传送 D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input ...
- 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 ...
- 快速切题CF 158B taxi 构造 && 82A double cola 数学观察 难度:0
实在太冷了今天 taxi :错误原因1 忽略了 1 1 1 1 和 1 2 1 这种情况,直接认为最多两组一车了 2 语句顺序错 double cola: 忘了减去n的序号1,即n-- B. Taxi ...
- B - Double Cola
Problem description Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double C ...
- codeforcess水题100道
之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型, ...
- BZOJ4614 [Wf2016]Oil
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
随机推荐
- [BZOJ2442][Usaco2011 Open]修剪草坪 dp+单调队列优化
2442: [Usaco2011 Open]修剪草坪 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1118 Solved: 569[Submit] ...
- Ubuntu角色登录答疑
1.su 命令验证出错: $ su - rootPassword: su: Authentication failureSorry. 这时候输入 $ sudo passwd rootEnter new ...
- 树上各种DFS姿势算法笔记
树是指由n个点,n-1条边构成的联通无向图.如果有一棵树,它的每一条边(u,v)都有一个权值l(u,v),我们把这样的树称作带权树. 我们知道对于树上的任意两个点,他们之间的路径是唯一的.对于两个点u ...
- 「kuangbin带你飞」专题二十 斜率DP
layout: post title: 「kuangbin带你飞」专题二十 斜率DP author: "luowentaoaa" catalog: true tags: mathj ...
- js部分的总结
一.词法结构 1.区分大小写 2.注意//单行/*多行注释* 3.字面量(直接量 literal) 12 //数字 5.8 //小数 “hello” ‘hello’ true /js/gi //正则 ...
- LA 3026 Period
这只是蓝书上的一道KMP水题...然后对于最长前缀的循环证明我就不说了... #include<iostream> #include<cstring> #include< ...
- Map泛型集合-输入名字输出成绩
package collection; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import ...
- 透视投影(Perspective Projection)变换推导
透视投影是3D固定流水线的重要组成部分,是将相机空间中的点从视锥体(frustum)变换到规则观察体(Canonical View Volume)中,待裁剪完毕后进行透视除法的行为.在算法中它是通过透 ...
- centos iptables关于ping
配置iptables策略后,一般来说INPUT都是DROP然后配置需要通过的 当执行: iptables -P INPUT DROP 后,机器就不能被ping通了! 因为icmp没有添加到规则中! 于 ...
- python的几个概念
1.函数在传递实参的时候是传递的是引用而不是从内存中重新赋相同值给形参. 2.函数名带圆括号和不带圆括号.函数名带圆括号是函数的调用,而函数名代表的是函数体. 3.函数返回值,在函数没有返回值的时候默 ...