hihocoder 1391 : Countries 北京网络赛(树状数组+离散化)
2016-09-27 23:15
337 查看
题目:http://www.hihocoder.com/problemset/problem/1391?sid=895605
官方题解:
分析:
我们可以预处理出导弹到达A的每个时间段,这样问题就转化成了求[x,x+TA]覆盖最大的时间段相应的代价和,这个范围内的导弹是可以防御住的,那么剩下的就是无法防御的。
所以用树状数组求解,时间的数据范围有点大,离散化一下即可。
代码:
官方题解:
分析:
我们可以预处理出导弹到达A的每个时间段,这样问题就转化成了求[x,x+TA]覆盖最大的时间段相应的代价和,这个范围内的导弹是可以防御住的,那么剩下的就是无法防御的。
所以用树状数组求解,时间的数据范围有点大,离散化一下即可。
代码:
using namespace std; typedef long long ll; const int N=1e5+9; ll c ; int lowbit(int x) { return x&(-x); } ll getsum(int x) { ll sum=0; for(int i=x; i>0; i-=lowbit(i))sum+=c[i]; return sum; } void add(int x,ll v) { for(int i=x; i<N; i+=lowbit(i))c[i]+=v; } struct Item { ll l,r,v; bool operator < (const Item& rhs)const { return r<rhs.r; } } a ; ll b ; map<ll,int>id; int main() { //freopen("f.txt","r",stdin); ll Ta,Tb,Sb,s,t,v; int n,m; while(~scanf("%lld%lld",&Ta,&Tb)) { memset(c,0,sizeof(c)); id.clear(); scanf("%lld",&Sb); scanf("%d%d",&n,&m); ll Eb=Tb+Sb,sum=0; int cnt=0; for(int i=1; i<=n; i++) { scanf("%lld%lld%lld",&s,&t,&v); if(s+t>=Sb&&s+t<=Eb) { a[cnt].l=s+2*t; a[cnt].r=s+2*t+(Eb-s-t)/(2*t)*2*t; a[cnt].v=v; cnt++; sum+=v; } } for(int i=1; i<=m; i++) { scanf("%lld%lld%lld",&s,&t,&v); a[cnt].l=s+t; a[cnt].v=v; sum+=v; if(s+2*t<Sb||s+2*t>Eb)a[cnt].r=a[cnt].l; else a[cnt].r=s+3*t+(Eb-s-2*t)/(2*t)*2*t; cnt++; } int tot=0; for(int i=0; i<cnt; i++) { b[tot++]=a[i].l; b[tot++]=a[i].r; b[tot++]=a[i].r-Ta; } sort(b,b+tot); tot=unique(b,b+tot)-b; for(int i=0; i<tot; i++)id[b[i]]=i+1; sort(a,a+cnt); ll ans=0; for(int i=0; i<cnt; i++) { add(id[a[i].l],a[i].v); ans=max(ans,getsum(id[a[i].r])-getsum(id[a[i].r-Ta]-1)); } printf("%lld\n",sum-ans); } return 0; }
相关文章推荐
- hihoCoder 1391 Countries【预处理+排序+优先队列】2016北京网络赛
- hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
- 2016北京网络赛 hihocoder 1391 Countries 树状数组
- hihocoder-1391&&北京网赛09 Countries(优先队列)
- 2016 ICPC 北京网络赛I题Countries,hiho1391 : Countries
- hihocoder 1391 树状数组
- hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
- 【HihoCoder1391】【排序】【堆】Countries 题解
- hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
- 【2016-北京赛区网络赛-I】枚举,贪心,优先队列,优化(导弹,hihocoder 1391)
- HihoCoder 1079 线段树 + 离散化
- 51NOD 1107 斜率小于0的连线数量 坐标离散化+树状数组
- HDU 3333 Turing Tree (离散化+离线处理+树状数组)
- poj 2299 Ultra-QuickSort(归并排序)||(树状数组+离散化)
- 10810-Ultra-QuickSort【逆序数、树状数组离散化】
- 南阳117求逆序数(离散化+树状数组或归并排序)
- HDU 5876 Disharmony Trees(离散化 树状数组)
- poj 2299 树状数组+离散化 or 归并排序 求逆序对
- hihoCoder - 1079 - 离散化 (线段树 + 离散化)
- 第十四个目标 FZU - 2236 离散化 树状数组