UVALive 3177 Beijing Guards
来源:互联网 发布:mac那个网站下载软件 编辑:程序博客网 时间:2024/05/24 06:42
偶数情况很好判断 奇数的时候 想了二分 但没想出怎么判断比较快 就放弃了 结果看了题解 就是二分额。。。 其实从左到右判断时 不用记录上一个人都选择了哪些数 只要记录在第一个人的范围内取了多少个 不在第一范围内取了多少个 另外n=1时要特判
#include<iostream>#include<cstdio>#include<cstring>#include<cctype>#include<cmath>#include<vector>#include<queue>#include<map>#include<algorithm>#define scnaf scanf#define cahr char#define bug puts("bugbugbug");#define LL long longusing namespace std;typedef long long ll;const int mod=1000000007;const int maxn=1e5+100;const int inf=1e9;const int maxe=200000;int a[maxn];int n;int lleft[maxn];int rright[maxn];int pd(int x){ int maxleft=a[0]; int maxright=x-a[0]; if(maxright<0) return 0; lleft[0]=a[0]; rright[0]=0; for(int i=1;i<n;i++) if(i%2==1){ int V=maxleft-lleft[i-1]; if(a[i]<=V){ lleft[i]=a[i]; rright[i]=0; } else { lleft[i]=V; rright[i]=a[i]-V; if(rright[i]+rright[i-1]>maxright)return 0; } } else { int V=maxright-rright[i-1]; if(a[i]<=V) { rright[i]=a[i]; lleft[i]=0; } else { rright[i]=V; lleft[i]=a[i]-V; if(lleft[i]+lleft[i-1]>maxleft)return 0; } } if(lleft[n-1]==0)return 1; return 0;}int main(){ while(scnaf("%d",&n) && n) { int ans=0; for(int i=0;i<n;i++) { scnaf("%d",&a[i]); if(i)ans=max(ans,a[i]+a[i-1]); } if(n==1) { printf("%d\n",a[0]); continue; } ans=max(ans,a[0]+a[n-1]); if(n%2) { int l=0,r=maxn; while(r>l) { int mid=l+(r-l)/2; if(pd(mid)) r=mid; else l=mid+1; } ans=r; } printf("%d\n",ans); }}
0 0
- UVALive - 3177 Beijing Guards
- UVALive 3177 Beijing Guards
- UVALIVE 3177 Beijing Guards
- UVALive - 3177 Beijing Guards 二分
- UVALive 3177 && uva 1335 Beijing Guards (贪心+二分)
- UVaLive 3177 Beijing Guards,CERC 2004,LA3117 题解
- LA 3177 Beijing Guards
- LA 3177 Beijing Guards 二分 -
- Beijing Guards
- Beijing Guards
- Beijing Guards
- Live Archive 3177 3177 - Beijing Guards 【枚举】
- LA 3177 UVA 1335 - Beijing Guards
- Live Archive 3177 - Beijing Guards 二分+贪心
- LA 3177 Beijing Guards (二分+贪心)
- Beijing Guards LA3177
- uva 1335 Beijing Guards
- uva 1335 - Beijing Guards
- IIS配置问题
- Spring-简要了解
- 小猪CMS修改登录入口和退出修改
- 2015.9.17总结
- 第四十一天 Path(画路径)、Bitmap、Slider(手机联系人首字母选项)
- UVALive 3177 Beijing Guards
- boostrap框架下的导航栏切换
- 获取某目录下的所有java源码文件名
- 一直按住ctrl+v,鼠标移动到不同的文本框粘贴,文本框的keyup事件失效
- Linux系统下部署maven nexus私服和手动同步中央仓库索引
- OpenWrt-LuCI 路由器设置端口映射(RDP & SSH)
- service
- 注解就是bean
- windos 环境下的java环境搭建