Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords (贪心)
作者:互联网
-
题意:你有\(a\)个树枝和\(b\)个钻石,\(2\)个树枝和\(1\)个钻石能造一个铁铲,\(1\)个树枝和\(2\)个钻石能造一把剑,问最多能造多少铲子和剑.
-
题解:如果\(a\le b\),若\(b\ge 2a\),那么一直取\(b\)即可,否则就要两两轮流减,即\((a+b)/3\),取个min即可.
-
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map> #include <set> #include <unordered_set> #include <unordered_map> #define ll long long #define fi first #define se second #define pb push_back #define me memset const int N = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; int t; int a,b; int main() { ios::sync_with_stdio(false);cin.tie(0); cin>>t; while(t--){ cin>>a>>b; if(a>b) swap(a,b); int ans=min(a,(a+b)/3); printf("%d\n",ans); } return 0; }
标签:Educational,Rated,const,int,Swords,cin,能造,include,define 来源: https://www.cnblogs.com/lr599909928/p/13107738.html