hihocoder-1391&&北京网赛09 Countries(优先队列)
题目链接:
Countries
描述
There are two antagonistic countries, country A and country B. They are in a war, and keep launching missiles towards each other.
It is known that country A will launch N missiles. The i-th missile will be launched at time Tai. It flies uniformly and take time Taci from one country to the other. Its damage capability is Dai.
It is known that country B will launch M missiles. The i-th missile will be launched at time Tbi.
It flies uniformly and takes time Tbci from one country to the other. Its damage capability is Dbi.
Both of the countries can activate their own defending system.
The defending system of country A can last for time TA, while The defending system of country B can last for time TB.
When the defending system is activated, all missiles reaching the country will turn around and fly back at the same speed as they come.
At other time, the missiles reaching the country will do damages to the country.
(Note that the defending system is still considered active at the exact moment it fails)
Country B will activate its defending system at time X.
When is the best time for country A to activate its defending system? Please calculate the minimal damage country A will suffer.
输入
There are no more than 50 test cases.
For each test case:
The first line contains two integers TA and TB, indicating the lasting time of the defending system of two countries.
The second line contains one integer X, indicating the time that country B will active its defending system.
The third line contains two integers N and M, indicating the number of missiles country A and country B will launch.
Then N lines follow. Each line contains three integers Tai, Taci and Dai, indicating the launching time, flying time and damage capability of the i-th missiles country A launches.
Then M lines follow. Each line contains three integers Tbi, Tbci and Dbi, indicating the launching time, flying time and damage capability of the i-th missiles country B launches.
0 <= TA, TB, X, Tai, Tbi<= 100000000
1 <= Taci, Tbci <= 100000000
0 <= N, M <= 10000
1 <= Dai, Dbi <= 10000
输出
For each test case, output the minimal damage country A will suffer.
提示
In the first case, country A should active its defending system at time 3.
Time 1: the missile is launched by country A.
Time 2: the missile reaches country B, and country B actives its defending system, then the missile turns around.
Time 3: the missile reaches country A, and country A actives its defending system, then the missile turn around.
Time 4: the missile reaches country B and turns around.
Time 5: the missile reaches country A and turns around.
Time 6: the missile reaches country B, causes damages to country B.
- 样例输入
-
2 2
2
1 0
1 1 10
4 5
3
2 2
1 2 10
1 5 7
1 3 2
0 4 8 - 样例输出
-
0
17 题意: A,B两国互发导弹,A发n个给了发射时间,到达另一国的时间,和伤害力,B发m个也是一样,
还有就是A,B两国的防御系统的开启时长,B国给了开启时间,现在问A国什么时候打开防御系统才能使伤害最小; 思路: 我们把有可能打到A国的导弹如果要它打在b国需要A国开启的时间段[l,r],然后就转变成了给了一些线段,线段有权值,然后完全覆盖才能取这个权值.然后求最大值;
右端点排序后,枚举左端点,优先队列维护就好了,也算是一个经典模型了; AC代码:#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e4+10;
int Ta,Tb,x,n,m,st[2*maxn],co[2*maxn],da[2*maxn],g[2*maxn];
struct node
{
int l,r,da;
}po[2*maxn];
int cmp(node a,node b)
{
return a.r<b.r;
}
struct MO
{
int l,da;
friend bool operator< (const MO &a ,const MO &b)
{
return a.l>b.l;
}
}ha;
priority_queue<MO>qu;
int main()
{
//freopen("int.txt","r",stdin);
while(scanf("%d%d",&Ta,&Tb)!=EOF)
{
while(!qu.empty())qu.pop();
scanf("%d",&x);
scanf("%d%d",&n,&m);
LL sum=0;
int cnt=0,u,v,w,num=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&u,&v,&w);
if(u+v>=x&&u+v<=x+Tb)
{
st[cnt]=u+v;
co[cnt]=v;
da[cnt]=w;
cnt++;
}
}
for(int i=1;i<=m;i++,cnt++)scanf("%d%d%d",&st[cnt],&co[cnt],&da[cnt]);
for(int i=0;i<cnt;i++)
{
sum=sum+da[i];
int temp=st[i]+2*co[i];int l=st[i]+co[i],r;
if(temp>=x&&temp<=Tb+x)
{
int len=(x+Tb-temp)/(2*co[i]);
r=temp+co[i]+len*2*co[i];
if(r-l>Ta)continue;
po[++num].l=l;po[num].r=r;po[num].da=da[i];
g[num]=l;
}
else
{
r=l;
po[++num].l=l;po[num].r=r;po[num].da=da[i];
g[num]=l;
}
}
sort(po+1,po+num+1,cmp);
sort(g+1,g+num+1);
LL ans=sum,d=0;
int fr=1;
g[0]=-1;
for(int i=1;i<=num;i++)
{
if(g[i]==g[i-1])continue;
int hi=g[i]+Ta;
while(po[fr].r<=hi&&fr<=num)
{
ha.l=po[fr].l;
ha.da=po[fr].da;
d=d+ha.da;
qu.push(ha);
fr++;
}
while(!qu.empty())
{
ha=qu.top();
if(ha.l<g[i])
{
qu.pop();
d=d-ha.da;
}
else break;
}
ans=min(ans,sum-d);
}
printf("%lld\n",ans);
}
}
hihocoder-1391&&北京网赛09 Countries(优先队列)的更多相关文章
- ACM学习历程—Hihocoder 1233 Boxes(bfs)(2015北京网赛)
hihoCoder挑战赛12 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There is a strange storehouse in PKU. In this ...
- 北京网赛I题 hiho1391 (树状数组、区间覆盖最大值问题)
题目链接:http://hihocoder.com/problemset/problem/1391 题意:A国和B国向对方分别投射N枚和M枚导弹(发射时间,飞行时间,伤害值),同时两国各自都有防御系统 ...
- hihoCoder1388 Periodic Signal(2016北京网赛F:NTT)
题目 Source http://hihocoder.com/problemset/problem/1388 Description Profess X is an expert in signal ...
- 2015年北京网赛 boxes(bfs)
题目链接: http://hihocoder.com/problemset/problem/1233 题目描述: 给定最多七个箱子,每个箱子的重量都不相同,每次都可以将一个箱子放在相邻的位置上,如果相 ...
- hihocoder-1389&&2016北京网赛07 Sewage Treatment(二分+网络流)
题目链接: Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people could ...
- hiho 1227 找到一个恰好包含n个点的圆 (2015北京网赛 A题)
平面上有m个点,要从这m个点当中找出n个点,使得包含这n个点的圆的半径(圆心为n个点当中的某一点且半径为整数)最小,同时保证圆周上没有点. n > m 时要输出-1 样例输入43 2 0 0 1 ...
- ACM学习历程—HDU5476 Explore Track of Point(平面几何)(2015上海网赛09题)
Problem Description In Geometry, the problem of track is very interesting. Because in some cases, th ...
- 离线树状数组 hihocoder 1391 Countries
官方题解: // 离线树状数组 hihocoder 1391 Countries #include <iostream> #include <cstdio> #include ...
- 2014年北京网络赛 Instrusive HDU 5040 题解 优先队列
网赛的时候看了这道题,发现就是平常的那种基础搜索题. 由于加了一个特殊条件:可以一次消耗3秒或原地停留1秒. 那就不能使用简单的队列了,需要使用优先队列才行. 题意 告诉一副地图:一个起点,一个终点, ...
随机推荐
- 线段树的区间更新---A Simple Problem with Integers
POJ 3468 Description 给出了一个序列,你需要处理如下两种询问. "C a b c"表示给[a, b]区间中的值全部增加c (-10000 ≤ c ≤ 100 ...
- 泛函编程(21)-泛函数据类型-Monoid
Monoid是数学范畴理论(category theory)中的一个特殊范畴(category).不过我并没有打算花时间从范畴理论的角度去介绍Monoid,而是希望从一个程序员的角度去分析Monoid ...
- ArrayList、Vector、HashMap、HashTable、HashSet的默认初始容量、加载因子、扩容增量
这里要讨论这些常用的默认初始容量和扩容的原因是: 当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全 ...
- QTimer太让人失望了,一秒触发一次事件都不准确。。
今天做项目中,我用QTimer来模拟数据生成,在另外的设备上接受.另外设备上有时1秒读不到数据,查询原因很久,终于发现是QTimer的问题. 测试代码如下 有兴趣同学可以自己试试. t = new Q ...
- [Tool] 使用CodeMaid自动程序排版
[Tool] 使用CodeMaid自动程序排版 前言 「使用StyleCop验证命名规则」这篇文章,指引开发人员透过StyleCop这个工具,来自动检验项目中产出的程序代码是否合乎命名规则. [Too ...
- python模块基础之json,requeste,xml,configparser,logging,subprocess,shutil。
1.json模块 json 用于[字符串]和 [python基本数据类型] 间进行转换(可用于不同语言之前转换),json.loads,将字符串转成python的基本数据类型,json.dum ...
- Emmet插件比较实用常用的写法
看了一些关于Emmet插件写法的文档,港真,怎么可以写这么长啊.其实知道几个大概要点加上实践基本就能上手写了啊 杂话 我前面有一篇[今天发现新大陆:haml和Emmet ],其实一开始的想法是写给自己 ...
- HTML <map> 标签-创建带有可点击区域的图像映射
定义和用法 定义一个客户端图像映射.图像映射(image-map)指带有可点击区域的一幅图像. 所有主流浏览器都支持 <map> 标签. 注释:area 元素永远嵌套在 map 元素内部. ...
- SharePoint 2010 ——自定义上传页面与多文件上传解决方案
最近项目遇到一个很麻烦的问题,原以为很容易解决,结果搞了那么久,先开个头,再慢慢写 SharePoint 2010 ——自定义上传页面与多文件上传解决方案 1.创建Sharepoint空白项目,创建应 ...
- svn 服务器不能看log问题
Subversion “show log” is offline 1.将/srv/svn/repos/ path svnserve.conf 里的 none-access = read 修改为none ...