【经典贪心】【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
- 【经典贪心】【bzoj 1707】: [Usaco2007 Nov]tanning分配防晒霜
- 1707: [Usaco2007 Nov]tanning分配防晒霜 (贪心)
- bzoj 1707: [Usaco2007 Nov]tanning分配防晒霜
- BZOJ 1707: [Usaco2007 Nov]tanning分配防晒霜
- bzoj1707[Usaco2007 Nov]tanning分配防晒霜
- [Usaco2007 Nov]tanning分配防晒霜
- 堆+贪心——nkoj1587【Usaco Nov07 Gold】分配防晒霜
- [BZOJ1640][Usaco2007 Nov]Best Cow Line 队列变换(贪心)
- BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间
- BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间
- bzoj 1706: [usaco2007 Nov]relays 奶牛接力跑
- BZOJ 1706 usaco2007 Nov relays 奶牛接力跑 倍增Floyd
- 【BZOJ 1642】 [Usaco2007 Nov]Milking Time 挤奶时间
- [倍增Floyd] BZOJ 1706 [usaco2007 Nov]relays 奶牛接力跑
- BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间
- BZOJ 1642 [Usaco2007 Nov]Milking Time 挤奶时间 排序+DP
- bzoj 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏 floyd
- bzoj 1642: [Usaco2007 Nov]Milking Time 挤奶时间(DP)
- 如何在ubuntu上安装java(64bit)
- ASP.net MVC--Htmlhelper
- iOS8 定位新增功能
- Android 之不同Activity间页面的跳转与传递参数
- malloc与new
- 【经典贪心】【bzoj 1707】: [Usaco2007 Nov]tanning分配防晒霜
- YUV格式详解(英文版)
- JavaAPI常用类及方法
- uses-permission权限列表
- 通信原理中的带宽指的是什么??
- poj3468A Simple Problem with Integers Splay版
- Linux下的 curl命令详解
- 任意矩形填充蛇形数字
- 将文字转化为拼音和全拼