zoukankan      html  css  js  c++  java
  • 2016-2017 ACM-ICPC, NEERC, Central Subregional Contest E

    Cupcakes

    题意:有n个人,k个蛋糕,每个人每次吃的蛋糕数最多为ai,ai最大的那个人最贪心,他每次都要吃ai个,轮到当某个人吃蛋糕时蛋糕没有了,那么这个人洗盘子,问能不能让最贪心的人洗盘子

    思路:暴力枚举吃i轮,每次存在一个ma 和 mi,表示最贪心的人前一个人经过i轮最多吃和最少吃第几块蛋糕(就是当前所有人一共吃了多少蛋糕),如果k在ma和mi之间,那么说明可行

    AC代码:

    #include "iostream"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #define ll long long
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a) memset(a,0,sizeof(a))
    using namespace std;
    const int N=1e5+100;
    ll a[N],n,k,p,ma,mi;
    int main(){
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        cin>>n>>k;
        for(int i=1; i<=n; ++i){
            cin>>a[i];
            if(a[i]>a[p]){
                p=i;
            }
            ma+=a[i];
        }
        mi=a[p]+n-1;
        ll x=0,c=ma-mi;
        for(int i=1; i<p; ++i){
            x+=a[i];
        }
        ll t1=k/mi,t2=k/ma;
        for(int i=0; i<=t1; ++i){
            ll mmi=i*mi+p-1, mma=i*ma+x;
            if(k>=mmi && k<=mma){
                cout<<"YES";
                return 0;
            }
        }
        cout<<"KEK";
        return 0;
    }
  • 相关阅读:
    2016年个人终结
    从一个程序员的角度看——微信小应用
    Spring 注解
    spring 大纲
    hibernate提纲
    spring基础
    eclipse如何利用userLibrary更好的分类jar
    【tomcat】There are no resources that can be added or removed from the server
    spring mvc 学习历程
    帝国CMS列表模板页面IF判断
  • 原文地址:https://www.cnblogs.com/max88888888/p/7123229.html
Copyright © 2011-2022 走看看