首页 技术 正文
技术 2022年11月19日
0 收藏 314 点赞 4,564 浏览 1010 个字

题目:https://www.luogu.org/problemnew/show/P2577

可以从只有一个窗口的角度思考出一个贪心结论。就是应当按吃饭时间(不算打饭时间)从大到小排序。这样交换相邻两个不会使答案更优,因为交换的话对其他人无影响,而吃饭时间长的那个人打到饭的时间也靠后了。

记录第一个窗口打完饭的时间在状态里。已知前 i 个人打饭时间和,能算出来第二个窗口打完饭的时间。所以值就可以记录总共的最晚结束时间了!也因为最晚结束时间对于打完饭的时间不是关系很紧密的,所以需要把第一个窗口的所有可能的打完饭的时间对应的结束时间记录下来。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=,M=N*N,INF=0x3f3f3f3f;
int n,f[][M],ans=INF,lm;
struct Node{
int a,b;
bool operator< (const Node &v) const
{return b>v.b;}
}t[N];
int rdn()
{
int ret=,fx=; char ch=getchar();
while(ch>''||ch<''){if(ch=='-')fx=-; ch=getchar();}
while(ch>=''&&ch<='') ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return ret*fx;
}
int main()
{
n=rdn();
for(int i=;i<=n;i++) t[i].a=rdn(),t[i].b=rdn();
sort(t+,t+n+);
memset(f,0x3f,sizeof f); f[][]=;
for(int i=,u=,v=;i<=n;i++,u=!u,v=!v)
{
lm+=t[i].a;
for(int j=,k1,k2;j<=lm;j++)
{
if(f[v][j])f[u][j]=max(f[v][j],lm-j+t[i].b);
if(j>=t[i].a)
f[u][j]=min(f[u][j],max(f[v][j-t[i].a],j+t[i].b));
}
}
int d=(n&);
for(int j=;j<=lm;j++) ans=min(ans,f[d][j]);
printf("%d\n",ans);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918