题目链接:Codeforces 651A Joysticks
题意:给定两个数
n
和
贪心模拟搞就可以了,每次将较大的减 2 。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define CLR(a, b) memset(a, (b), sizeof(a))
using namespace std;
typedef long long LL;
typedef pair<int, char> pii;
const int MAXN = 1000+10;
const int INF = 0x3f3f3f3f;
void getmax(int &a, int b) {a = max(a, b); }
void getmin(int &a, int b) {a = min(a, b); }
int main()
{
int x, y; cin >> x >> y;
int ans = 0;
while(1)
{
if(x > y) swap(x, y);
if(x == 2 && y == 2) {
ans++;
break;
}
if(x == 1 && y == 2) {
ans++;
break;
}
if(x == 1 && y == 1) {
break;
}
if(y & 1) {
ans += y / 2;
x += y / 2;
y = 1;
}
else {
ans += y / 2 - 1;
x += y / 2 - 1;
y = 2;
}
//cout << x << " " << y << endl;
}
cout << ans << endl;
return 0;
}