bzoj1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
来源:互联网 发布:c语言strstr函数用法 编辑:程序博客网 时间:2024/06/10 12:17
1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 663 Solved: 291
[Submit][Status][Discuss]
Description
Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of the cows to clean the barn. Farmer John has N (1 <= N <= 10,000) cows who are willing to do some cleaning. Because dust falls continuously, the cows require that the farm be continuously cleaned during the workday, which runs from second number M to second number E during the day (0 <= M <= E <= 86,399). Note that the total number of seconds during which cleaning is to take place is E-M+1. During any given second M..E, at least one cow must be cleaning. Each cow has submitted a job application indicating her willingness to work during a certain interval T1..T2 (where M <= T1 <= T2 <= E) for a certain salary of S (where 0 <= S <= 500,000). Note that a cow who indicated the interval 10..20 would work for 11 seconds, not 10. Farmer John must either accept or reject each individual application; he may NOT ask a cow to work only a fraction of the time it indicated and receive a corresponding fraction of the salary. Find a schedule in which every second of the workday is covered by at least one cow and which minimizes the total salary that goes to the cows.
Input
* Line 1: Three space-separated integers: N, M, and E. * Lines 2..N+1: Line i+1 describes cow i's schedule with three space-separated integers: T1, T2, and S.
Output
* Line 1: a single integer that is either the minimum total salary to get the barn cleaned or else -1 if it is impossible to clean the barn.
Sample Input
0 2 3 //一号牛,从0号stall打扫到2号,工资为3
3 4 2
0 0 1
INPUT DETAILS:
FJ has three cows, and the barn needs to be cleaned from second 0 to second
4. The first cow is willing to work during seconds 0, 1, and 2 for a total
salary of 3, etc.
Sample Output
HINT
约翰有3头牛,牛棚在第0秒到第4秒之间需要打扫.第1头牛想要在第0,1,2秒内工作,为此她要求的报酬是3美元.其余的依此类推. 约翰雇佣前两头牛清扫牛棚,可以只花5美元就完成一整天的清扫.
Source
Silver
正解是线段树?用dp水过。
<span style="font-size:18px;">#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#define ll long long#define N 10005#define inf 1000000000using namespace std;int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}struct Node{int t1,t2,s;}a[N];bool cmp(Node a,Node b){ return (a.t1!=b.t1)?(a.t1<b.t1):((a.t2!=b.t2)?(a.t2<b.t2):(a.s<b.s));}int n,m,e,ans,f[N];int main(){ n=read();m=read();e=read(); for(int i=1;i<=n;i++)a[i].t1=read(),a[i].t2=read(),a[i].s=read(); sort(a+1,a+1+n,cmp); ans=inf; for(int i=1;i<=n;i++)f[i]=inf; for(int i=1;i<=n;i++)if(a[i].t1<=m)f[i]=a[i].s; for(int i=2;i<=n;i++) for(int j=1;j<i;j++) if(a[i].t1<=a[j].t2+1) { f[i]=min(f[i],f[j]+a[i].s); if(a[i].t2>=e)ans=min(ans,f[i]); } ans=(ans==inf)?-1:ans; cout<<ans<<endl; return 0;}</span>
好吧,来段zyf写的正解。%%%。
<span style="font-size:18px;">#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<iostream>#include<vector>#include<map>#include<set>#include<queue>#include<string>#define inf 100000000000#define maxn 80000+2000#define maxm 500+100#define eps 1e-10#define ll long long#define pa pair<int,int>#define for0(i,n) for(int i=0;i<=(n);i++)#define for1(i,n) for(int i=1;i<=(n);i++)#define for2(i,x,y) for(int i=(x);i<=(y);i++)#define for3(i,x,y) for(int i=(x);i>=(y);i--)#define mod 1000000007using namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} return x*f;}struct rec{int l,r;ll w;}a[maxn];struct seg{int l,r;ll mi,tag;}t[4*maxn];int n,x,y;inline bool cmp(rec a,rec b){ return a.l<b.l||(a.l==b.l&&a.r<b.r);}inline void pushup(int k){ t[k].mi=min(t[k<<1].mi,t[k<<1|1].mi);}inline void update(int k,ll z){ t[k].mi=min(t[k].mi,z); t[k].tag=min(t[k].tag,z);}inline void pushdown(int k){ if(t[k].tag==inf)return ; update(k<<1,t[k].tag); update(k<<1|1,t[k].tag); t[k].tag=inf;}inline void build(int k,int x,int y){ int l=t[k].l=x,r=t[k].r=y,mid=(l+r)>>1;t[k].tag=inf; if(l==r){t[k].mi=l==0?0:inf;return ;} build(k<<1,l,mid);build(k<<1|1,mid+1,r); pushup(k);}inline ll query(int k,int x){ int l=t[k].l,r=t[k].r,mid=(l+r)>>1; if(l==r)return t[k].mi; pushdown(k); if(x<=mid)return query(k<<1,x);else return query(k<<1|1,x);}inline void change(int k,int x,int y,ll z){ int l=t[k].l,r=t[k].r,mid=(l+r)>>1; if(l==x&&r==y){update(k,z);return;} pushdown(k); if(y<=mid)change(k<<1,x,y,z); else if(x>mid)change(k<<1|1,x,y,z); else change(k<<1,x,mid,z),change(k<<1|1,mid+1,y,z); pushup(k);}int main(){ freopen("A.in","r",stdin); freopen("A.out","w",stdout); n=read();x=read();y=read(); for1(i,n) { a[i].l=read()-x+1;a[i].r=read()-x+1;a[i].w=read(); if(a[i].l<=0)a[i].l=1; } sort(a+1,a+n+1,cmp); build(1,0,y-x+1); for1(i,n) { if(a[i].r<a[i].l)continue; if(a[i].r<=0)continue; if(a[i].l>y-x+1)continue; ll t=query(1,a[i].l-1); if(t!=inf)change(1,a[i].l,min(a[i].r,y-x+1),t+a[i].w); } //for1(i,n)cout<<a[i].l<<' '<<a[i].r<<' '<<a[i].w<<endl; //for1(k,8*n)cout<<t[k].l<<' '<<t[k].r<<' '<<t[k].mi<<' '<<t[k].tag<<endl; ll ans=query(1,y-x+1); printf("%lld\n",ans==inf?-1:ans); return 0;}</span>
- bzoj1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
- BZOJ1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
- 【bzoj1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚
- bzoj1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
- [BZOJ1672]Usaco 2005 Dec Cleaning Shifts 清理牛棚
- bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(DP)
- bzoj1672【Usaco2005Dec】Cleaning Shifts 清理牛棚
- 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 DP + 线段树 / SPFA
- BZOJ 1672 Usaco 2005 Dec Cleaning Shifts 清理牛棚 动态规划
- bzoj3389 [Usaco2004 Dec]Cleaning Shifts安排值班
- bzoj3389: [Usaco2004 Dec]Cleaning Shifts安排值班
- 【bzoj3389】[Usaco2004 Dec]Cleaning Shifts安排值班
- bzoj 3389 [Usaco2004 Dec]Cleaning Shifts安排值班
- 【BZOJ】3389: [Usaco2004 Dec]Cleaning Shifts安排值班
- Cleaning Shifts
- Cleaning Shifts
- Cleaning Shifts
- - Cleaning Shifts
- vmware tools安装以及分辨率更改
- [LeetCode-66] Plus One
- mingw下vs编译的ffmpeg如何支持x264
- Ruby版本管理(RVM)
- asp.net上传文件使用fileupload控件,判断文件类型和大小,取得文件路径时报错【System.IO.FileNotFoundException:未能找到文件】的解决办法
- bzoj1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
- MySQL卸载
- 多线程同步方法<一>数据库悲观锁(for update)
- 分页查询
- QT5程序发布--打包可执行文件和动态链接库
- Android 线程之Message 的使用
- jQuery效果之tab
- shiro权限框架中的认证和授权过程
- UVa11796 - Dog Distance(二维几何)