蒟蒻想问问各位大佬 为什么这题不能用贪心 30分wuwu~
查看原帖
蒟蒻想问问各位大佬 为什么这题不能用贪心 30分wuwu~
381680
woshipipixia楼主2020/9/10 20:30
#include<bits/stdc++.h>
using namespace std;
struct node
{
    double eff;
    long long x;
    long long y;
}a[10005];
bool cmp(struct node a,struct  node b)
{
    return a.eff<b.eff;
}
int main()
{
    long long t,m;
    cin>>t>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        a[i].eff=y/x;
        a[i].x=x;
        a[i].y=y;
    }
    sort(a+1,a+m+1,cmp);
    long long ans=0;
    for(int i=m;i>=1;)
        {
            if(a[i].x<=t)
            {
                ans+=(t*a[i].y)/a[i].x;
                t-=t/a[i].x;
            }
                i--;
        }
    cout<<ans;
    return 0;
}

用了贪心 想知道为什么是不对的 能否举个例子

2020/9/10 20:30
加载中...