zoukankan      html  css  js  c++  java
  • Codeforces 371C Hanburgers

    Can I use Chinese?
    这个题是一道二分题目 
    he question is a two-point question. 
    题意很简单,不需要解释了

    It is very simple, do not need to explain. 

    但是我一直没过样例,原因是我的变量类型搞错了 

    But I haven't had the sample because my variables are wrong. 
    应该是`long long`,但是我写成了`int` 
    It should be `long long`, but I use the `int`. 
    下面是代码 
    Next is my code. 

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    int q[5]; // B C S
    int c[5];
    int m[5];
    char s[110];
    int B,C,S;
    long long tot,ans;
    int check(long long n)
    {
        long long tmp=tot;
        if(n*c[1]>q[1])    tmp-=(n*c[1]-q[1])*m[1];
        if(n*c[2]>q[2])    tmp-=(n*c[2]-q[2])*m[2];
        if(n*c[3]>q[3])    tmp-=(n*c[3]-q[3])*m[3];
        if(tmp>=0)
            return 1;
        else
            return 0;
    }
    int main()
    {
        cin>>s;
        for(int i=0;i<strlen(s);i++)
        {
        if(s[i]=='B')    c[1]++;
        if(s[i]=='S')    c[2]++;
        if(s[i]=='C')    c[3]++;
        }
        cin>>q[1]>>q[2]>>q[3];
        cin>>m[1]>>m[2]>>m[3];
        cin>>tot;
        int d=tot;
        long long l=1,r=2333333333333;
        long long mid;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(check(mid))
            l=mid+1,ans=mid;
            else    r=mid-1;
        }
        cout<<ans;
        return 0;
    
    }
            

    还可以用贪心
    贪心就比较好想了

    尽可能地将原有材料耗光,然后买

    #include<iostream>
    #include<cstdio>
    #include<cstring> 
    #include<cmath>
    using namespace std;
    int nb,ns,nc;
    int mb,ms,mc;
    long long m;
    char a[109];
    int B,S,C;
    long long ans;
    int main()
    {
        cin>>a;
        for(int i=0;i<strlen(a);i++)
        {
            if(a[i]=='B') B++;
            if(a[i]=='C') C++;
            if(a[i]=='S') S++;
        }
        cin>>nb>>ns>>nc;
        cin>>mb>>ms>>mc;
        cin>>m;
        
        int minn=233333333;
        if(B) minn=min(minn,nb/B);
        if(C) minn=min(minn,nc/C);
        if(S) minn=min(minn,ns/S);
        ans+=minn;
        ns-=S*minn;nb-=B*minn;nc-=C*minn;
        
        if(S==0) ns=0;
        if(C==0) nc=0;
        if(B==0) nb=0;
        
        int zz=B*mb+C*mc+S*ms;
        int tot=0;
        
        while(nb!=0||ns!=0||nc!=0)
        {
            tot=0;
            if(nb>=B)
                nb-=B;
            else
            {
                tot+=(B-nb)*mb;
                nb=0;
            }
            if(nc>=C)
                nc-=C;
            else
            {
                tot+=(C-nc)*mc;
                nc=0;
            }
            if(ns>=S)
                ns-=S;
            else
            {
                tot+=(S-ns)*ms;
                ns=0;
            }
            if(tot>m)
                break;
            else
                m-=tot,ans++; 
        }
        ans+=m/zz;
        cout<<ans;
        return 0;
    } 
    View Code
  • 相关阅读:
    T100添加合计
    T100整单操作维护交运方式
    错误代码:11300001 数据集配置错误Query:ORA-01652: 无法通过 128 (在表空间 TEMP 中) 扩展 temp 段
    T100 技术汇总
    帆软取年月常用函数
    使用oracle DB_LINK的一个注意点
    单行拆转多行的查询
    SQL-Oracle内实现柱形图式的效果
    SQL-删除重复记录
    MERGE语法详解
  • 原文地址:https://www.cnblogs.com/oiersyp/p/7028420.html
Copyright © 2011-2022 走看看