zoukankan      html  css  js  c++  java
  • Greedy Takahashi——UPC

    题目描述

    Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times:
    ·If Takahashi has one or more cookies, eat one of his cookies.
    ·Otherwise, if Aoki has one or more cookies, eat one of Aoki’s cookies.
    ·If they both have no cookies, do nothing.
    In the end, how many cookies will Takahashi and Aoki have, respectively?

    Constraints
    ·0≤A≤1012
    ·0≤B≤1012
    ·0≤K≤1012
    ·All values in input are integers.

    输入

    Input is given from Standard Input in the following format:

    A B K

    输出

    Print the numbers of Takahashi’s and Aoki’s cookies after K actions.

    样例输入

    【样例12 3 3
    【样例2500000000000 500000000000 1000000000000
    

    样例输出

    【样例10 2
    【样例20 0
    

    提示

    样例1解释
    Takahashi will do the following:
    ·He has two cookies, so he eats one of them.
    ·Now he has one cookie left, and he eats it.
    ·Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.
    Thus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.
    ——————————————————————————————————————————————————————————————————
    很水,直接放代码

    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    //#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const int maxn = 2e5 + 7;
    const int mod = 1e9 + 7;
    #define start int wuyt()
    #define end return 0
    start{
        ll a,b,k;
        cin>>a>>b>>k;
        if(k<=a) cout<<a-k<<" "<<b<<endl;
        else if(k<=a+b) cout<<0<<" "<<b+a-k<<endl;
        else cout<<0<<" "<<0<<endl;
        end;
    }
     
    /**************************************************************
        Language: C++
        Result: 正确
        Time:1 ms
        Memory:2024 kb
    ****************************************************************/
    
  • 相关阅读:
    JavaScript 学习笔记之最终篇
    JavaScript 学习笔记(三)
    JavaScript 学习笔记(一)
    JAVA 多线程机制(二)
    JAVA 多线程机制(一)
    apache配置CA证书通过https通信
    httpd的一些知识点
    Elasticsearch安装图形化界面工具Head插件
    Logstash收集nginx访问日志和错误日志
    lvm管理卷之缩减卷大小
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144187.html
Copyright © 2011-2022 走看看