Drink It (模拟)水

Drink It

Problem Description

来来来,做道题,一起防老年痴呆。啤酒2元一瓶,4个瓶盖换一瓶,2个空瓶换一瓶。问:n元可换几瓶。不可以赊账不可以买半瓶酒.

Input

多组数据,输入文件第一行是一个整数T,接下来T行,每行一个整数n(0<=n<=10000000)

Output

问最多能够得到多少瓶啤酒

Sample Input

2

0

10

Sample Output

0

15

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define N 100010
#define M 1000000007
using namespace std;
int main()
{
	int i,j,k;
	int n,m,t;
	scanf("%d",&t);
	while(t--)
	{
		int sum=0;
		scanf("%d",&n);
		int p=n/2;
		int pg=p;
		sum+=p;
		while(1)
		{
			if(p>=2)
			{
				int s=p/2;
				sum+=s;p=p-(2*s)+s;pg+=s;
			}
			if(pg>=4)
			{
				int ss=pg/4;
				sum+=ss;p+=ss;pg=pg-(4*ss)+ss;
			}
			if(p<2&&pg<4)
				break;
		}
		printf("%d\n",sum);
	}
	return 0;
}
F 


 

你可能感兴趣的:(Drink It (模拟)水)