Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords (贪心)

Posted lr599909928

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords (贪心)相关的知识,希望对你有一定的参考价值。

技术图片

  • 题意:你有(a)个树枝和(b)个钻石,(2)个树枝和(1)个钻石能造一个铁铲,(1)个树枝和(2)个钻石能造一把剑,问最多能造多少铲子和剑.

  • 题解:如果(ale b),若(bge 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
    ",ans);
    	 }
    
        return 0;
    }
    

以上是关于Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords (贪心)的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27