UVALive 7261 Xiongnu's Land(二分)
来源:互联网 发布:python 判断加载完成 编辑:程序博客网 时间:2024/06/08 23:36
题目地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5273
思路:二分位置(无需考虑总坐标,仅考虑横坐标即可),使得2*area >= sum,在满足该条件的情况下,尽量右移使得左侧面积尽量大。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define debuusing namespace std;const int maxn=1e4+50;typedef long long LL;struct Node{ int l,r,h;};int t,R,n;Node a[maxn];LL cal(int x){ LL sum=0; for(int i=0; i<n; i++) if(a[i].l<x) sum+=(LL)(min(a[i].r,x)-a[i].l)*a[i].h; return sum;}int main(){#ifdef debug freopen("in.in","r",stdin);#endif // debug scanf("%d",&t); while(t--) { LL sum=0; scanf("%d",&R); scanf("%d",&n); for(int i=0; i<n; i++) { int x,y,w,h; scanf("%d%d%d%d",&x,&y,&w,&h); a[i].l=x,a[i].r=x+w,a[i].h=h; sum+=(LL)w*h; } int l=0,r=R,mid; while(l<r) { mid=(l+r)/2; LL area=cal(mid); if(2*area<sum) l=mid+1; else r=mid; } LL tmp=cal(r); while(cal(r)==tmp&&r<=R) r++; printf("%d\n",r-1); } return 0;}
0 0
- UVALive 7261 Xiongnu's Land(二分)
- UVALive 7261 Xiongnu's Land(二分)
- UVALive 7261 A - Xiongnu's Land(二分)
- Xiongnu's Land (UVALive
- UVALive 7261 Xiongnu's Land 扫描线
- UVALive 7261 A - Xiongnu's Land
- 【扫描线】uvalive 7261 Xiongnu's Land
- hihoCoder 1249 Xiongnu's Land(二分)
- 二分 hihoCoder1249 Xiongnu's Land
- UVA 7261 Xiongnu's Land
- Xiongnu's Land (线性扫描,二分)
- 2015 Asia BeiJing Regional Contest A. Xiongnu's Land(二分)
- hiho 1249 Xiongnu's Land
- hihocoder 1249 Xiongnu's Land
- 2015北京区域赛 A.Xiongnu's Land(二分或者标记法)
- HDU 5124 hihocoder 1249 Xiongnu's Land (2015北京区域赛A)
- 2015ACM-ICPC 北京赛区 Problem A. Xiongnu's Land
- hdu 1507 Uncle Tom's Inherited Land* (二分匹配)
- 《入门经典》2
- JDBC PreparedStatement接口的应用
- android面试(基础篇 9)
- activity的双向传值
- Ubuntu 14.04 ssh的安装和配置
- UVALive 7261 Xiongnu's Land(二分)
- hdu4707Pet最短路(spfa)
- [2482]二叉排序树
- 二叉排序树
- ORACLE的 数据装载 sql loader
- sudsn 转自豆瓣 LPTHW习题
- Ajax异步请求RESTFUL API之跨域问题解决方案
- Java算法——判断一个数是否是回文数
- RTCP协议详解