zoukankan      html  css  js  c++  java
  • 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;
      }
      
  • 相关阅读:
    es5和es6的区别
    如何将word文档内容在网页显示方法
    实现在线浏览PDF文件的方法
    移动端开发兼容问题
    常见的浏览器兼容问题和解决方法
    弹层
    猜数字游戏
    米字格画布
    时钟制作
    关于屏幕高度
  • 原文地址:https://www.cnblogs.com/lr599909928/p/13107738.html
Copyright © 2011-2022 走看看