ACM International Collegiate Programming Contest, Egyptian Collegiate Programming Contest Problem K

Problem K. Katryoshka
Input file: katryoshka.in
Output file: standard output
Balloon Color: White
The Egyptian football team will be in Russia for the World Cup, of course they all would like to buy
souvenirs for their families. Luckily they met the king of souvenirs of the famous Russian souvenir
Matryoshka; the king makes his masterpiece Katryoshka using different kinds of pieces: wooden eyes,
wooden mouths, and wooden bodies. He can form a nice Katryoshka using one of the following ways:
• Two eyes and a body.
• Two eyes, mouth and a body.
• Eye, mouth and a body.
If the king has n eyes, m mouths and k bodies, what is the largest number of Katryoshkas that can be
made by the king?
Input
The first line of the input contains a single integer 1 ≤ T ≤ 100 the number of test cases. Each test case
consists of a single line containing 3 space separated integers ‘n m k’ the number of eyes, mouths and
bodies respectively; where 0 ≤ n, m, k ≤ 108
.
Output
For each test case output a line displaying the case number and a single integer which is the largest
number of nice Katryoshka pieces.
Example
katryoshka.in standard output
4
1 2 3
0 11 2
14 21 23
90 24 89
Case 1: 1
Case 2: 0
Case 3: 14
Case 4: 57

简单的贪心就好了;

首先肯定是选1~1~1比例的,
第二种肯定是不选的,如果 eyes 还有剩余,再选第一种方案;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 100005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-5
#define pll pair<ll,ll>
#define lson 2*x
#define rson 2*x+1

long long  qupower(int a, int b) {
    long long  ans = 1;
    while (b) {
        if (b & 1)ans = ans * a;
        b >>= 1;
        a = a * a;
    }
    return ans;
}

inline int read() {
    int an = 0, x = 1; char c = getchar();
    while (c > '9' || c < '0') {
        if (c == '-') {
            x = -1; 
        }
        c = getchar();
    }
    while (c >= '0'&&c <= '9') {
        an = an * 10 + c - '0'; c = getchar();
    }
    return an * x;
}



int main() {
    ios::sync_with_stdio(false);
    freopen("katryoshka.in","r",stdin);
     int t;
    cin>>t;
    int cnt=0;
    while(t--){
        cnt++;

        int n,m,k;
        cin>>n>>m>>k;
        int ans=0;
        int tt=min(n,m);
        ans+=tt;
        n-=tt;
        if(n>0){
            ans+=n/2;
        }
        ans=min(ans,k);
        cout<<"Case "<<cnt<<": ";
        cout<<ans<<endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值