`
bcyy
  • 浏览: 1824768 次
文章分类
社区版块
存档分类
最新评论

Codeforces A. Double Cola 题解

 
阅读更多

题目很奇怪,就是5个人排队喝可乐,喝完之后编程两个人,然后拍在队后面,然后继续喝可乐。

给出个数值,代表第几罐可乐,问会是第几个人喝到?

http://codeforces.com/problemset/problem/82/A

一个数学问题,仔细点就好了。


要熟练的知识点:

1 要熟悉解决这种递增数列,如何减去循环部分

2 要知道如何计算,求余取答案

#include <string>
#include <iostream>
using namespace std;

void DoubleCola()
{
	string strs[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};
	int n = 0;
	cin>>n;

	int i = 1;
	while (n > i*5)//100 - 5 - 10 - 20 - 40 ...
	{
		n -= i*5;
		i <<= 1;
	}
	int a = n / i;
	if (n % i) a++;
	cout<<strs[a-1];
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics