---
title: "Codeforces A. Double Cola 题解"
author: "bcyy"
date: "2014-04-29T18:16:00Z"
tags: []
slug: "codeforces-a-double-cola"
draft: false
lastmod: "2014-04-30T09:08:07Z"
id: 2057717
url: "https://bcyy.iteye.com/blog/2057717"
---

题目很奇怪，就是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];
}
```