【经典贪心】【bzoj 1707】: [Usaco2007 Nov]tanning分配防晒霜

来源:互联网 发布:mac 恢复模式打开终端 编辑:程序博客网 时间:2024/04/28 23:24

http://www.lydsy.com/JudgeOnline/problem.php?id=1707


啊这么简单的贪心都不会。。。。。要是比赛只会匹配等TLE。。。。


pty:

如:按spf从小到大排序,从当前可选集合中选出合法的,再按max从小到大排序,选择前sum个即可

证明:这个应该是可以从证明不存在增广路的角度来看的:就是目前贪心地选了,以后肯定存在某种修改使答案又增加了

发现usaco月赛题编程复杂度都很低,狗眼观察力要比较强。。。



//#define _TEST _TEST#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <cmath>#include <algorithm>using namespace std;/************************************************Code By willinglive    Blog:http://willinglive.cf************************************************/#define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++)#define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--)#define MS(arr,x) memset(arr,x,sizeof(arr))#define LL long long#define INE(i,u,e) for(int i=head[u];~i;i=e[i].next)inline const int read(){int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}/////////////////////////////////////////////////int c,l;struct spf{int mx,mi;}a[2510];struct data{int x,cnt;}b[2520];/////////////////////////////////////////////////bool cmp(const spf &a,const spf &b){return a.mx<b.mx;}bool cmp2(const data &a,const data &b){return a.x<b.x;}/////////////////////////////////////////////////void input(){    cin>>c>>l;    rep(i,1,c) a[i].mi=read(), a[i].mx=read();    rep(i,1,l) b[i].x=read(), b[i].cnt=read();    sort(&a[1],&a[c+1],cmp);    sort(&b[1],&b[l+1],cmp2);}void solve(){int ans=0;rep(i,1,c){rep(j,1,l) if(b[j].cnt){if(a[i].mi<= b[j].x && b[j].x<=a[i].mx){b[j].cnt--;ans++;break;}}}cout<<ans<<endl;}/////////////////////////////////////////////////int main(){    #ifndef _TEST    freopen("std.in","r",stdin); freopen("std.out","w",stdout);    #endif    input(),solve();    return 0;}


0 0
原创粉丝点击