codeforces #345 div2 A. Joysticks (贪心)
题目链接 题意:两个手柄? 初始的电量给出,只有一个充电器,每经过一秒,充着电的手柄电量增加1,没有充电的手柄电量减少2,允许电量充到0以上,当有电量为0的时候,或者当某一分钟开始的时候有手柄电量为1,游戏立即结束。问最多能玩多少时间游戏。
思路:贪心。。每次给电量少的充电。 坑点在于当某一时刻有手柄电量为1,那么游戏在进行这一分钟之前就结束。
/* ***********************************************
Author :111qqz
Created Time :2016年03月07日 星期一 17时06分41秒
File Name :code/cf/#345/A.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6int a,b;
7int main()
8{
9 #ifndef ONLINE_JUDGE
10 freopen("code/in.txt","r",stdin);
11 #endif
12 cin>>a>>b;
13 int cnt = 0 ;
14 while (1)
15 {
16 if (a>b)
17 {
18 a-=2;
19 if (a<0) break;
20 b++;
21 }
22 else
23 {
24 a++;
25 b-=2;
26 if (b<0) break;
27 }
28 cnt++;
29 // if (a==1&&b==1) break;
30 if (a<=0||b<=0) break;
31 }
32 cout<<cnt<<endl;
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}