hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1391 : Countries
时间限制:1000ms单点时限:1000ms内存限制:256MB描述
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
题目链接:
http://hihocoder.com/problemset/problem/1391
题目大意:
A和B两个国家互射导弹,每个国家都有一个防御系统,在防御系统开启的时间内可以将到达本国的导弹反弹回去(掉头,防御系统不能开开关关)。
现在已知:Ta、Tb为A、B两国导弹防御能开启的持续时间,X为B国开启导弹防御系统的时刻(持续时间为[X,Tb+X],包含端点)
A向B发射N枚导弹,B向A发射M枚导弹。每枚导弹有3个值:发射时间,从A到B或从B到A的飞行时间,伤害值。
现在A可以在任意时刻开启防御系统,求A所受到的最小伤害值。
题目思路:
【预处理+排序+堆】
首先预处理,求出每枚导弹不会打到A需要A国防御系统开启的时间段[st,et],只有A开启防御的时间段[Y,Y+Ta]包含[st,et]那么这枚导弹不会打到A。
预处理之后将每枚导弹按照et从小到大排序。
从1到n+m枚导弹,对于当前这枚导弹,如果需要被防御,那么A防御系统的结束时间就为et,那么开启时间就为et-Ta
那么将之前已经被防御的导弹中st<et-Ta的移除出去,表示这些导弹不能在当前决策中被防御。
可以开个STL的优先队列或者堆记录之前被防御的导弹序号,按照st从小到大存,每次比较最小的st和开启时间et-Ta。并在过程中增减伤害值,并记录最小伤害。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 20004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int Ta,Tb,X,sum;
struct xxx
{
LL st,ct,et,d;
}a[N],b[N];
struct cmp1
{
bool operator ()(const int &aa,const int &bb)
{
return a[aa].st>a[bb].st;
}
};
bool cmp(xxx aa,xxx bb)
{
return aa.et<bb.et;
}
int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
while(~scanf("%d%d",&Ta,&Tb))
{
lll=;ans=MAX;sum=;
scanf("%d%d%d",&X,&n,&m);
for(i=;i<=n;i++)
{
scanf("%d%d%d",&b[i].st,&b[i].ct,&b[i].d);
b[i].et=b[i].st+b[i].ct;
if(b[i].et>=X && b[i].et<=X+Tb)
{
sum+=b[i].d;
a[++lll].st=b[i].et+b[i].ct;
j=Tb+X-a[lll].st;
j=j%(*b[i].ct);
a[lll].et=Tb+X-j;
a[lll].d=b[i].d;
if(j>=b[i].ct)a[lll].et+=b[i].ct+b[i].ct;
if(a[lll].st+b[i].ct<X || a[lll].st>Tb+X)a[lll].et=a[lll].st;
}
}
for(i=;i<=m;i++)
{
scanf("%d%d%d",&b[i].st,&b[i].ct,&b[i].d);
b[i].et=b[i].st+b[i].ct;
sum+=b[i].d;
a[++lll].st=b[i].et;
j=Tb+X-a[lll].st;
j=j%(*b[i].ct);
a[lll].et=Tb+X-j;
a[lll].d=b[i].d;
if(j>=b[i].ct)a[lll].et+=b[i].ct+b[i].ct;
if(a[lll].st+b[i].ct<X || a[lll].st>Tb+X)a[lll].et=a[lll].st;
}
sort(a+,a+lll+,cmp);
priority_queue<int,vector<int>,cmp1>q; for(i=;i<=lll;i++)
{
q.push(i);y=a[i].et;
sum-=a[i].d;
x=q.top();
while(y-a[x].st>Ta && !q.empty())
{
sum+=a[x].d;
q.pop();x=q.top();
}
ans=min(ans,sum);
}
printf("%d\n",ans);
}
return ;
}
/*
// //
*/
hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)的更多相关文章
- hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
- hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...
- hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...
- hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
- hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】
https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 当时忽略了一个重要问题,就是ax*ay要最小时,x.y可以相等,那就简单 ...
- 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...
- 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum
题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...
随机推荐
- C# 内存管理优化实践
内存优化畅想系列文章已经结束了,很多读者读完之后可能觉得“然并卵”,毕竟都是给微软提的建议而已,现在都没有实现.那么为了优化内存,有没有什么我们现在就能用的技巧呢?我的答案是:有.网上关于.net内存 ...
- app包中的fragment和v4包中的fragment的使用的区别
app包中的fragment和v4包中的fragment的使用的区别 1.尽量不要用app包中的fragment,因为这个是在3.0之后才有的,支持的版本太高,在低版本中是是用不了的 2.androi ...
- C#和asp.net中链接数据库中 参数的几种传递方法
#region 参数传递方法第一种 //参数设置方法(第一种) //SqlParameter sp = new SqlParameter("@Name", str_Name); / ...
- 哈哈,CSDN又支持Windows Live Writer了
从10年开始写CSDN博客,后面不支持WLW了,就不怎么写了,话说自带的编辑器确实不怎么样,不过又支持了,那就哈哈,重新开工了. 关于如何配置的,跟以前一样,详情如下所示: http://blog.c ...
- 关于Asp.Net中避免用户连续多次点击按钮,重复提交表单的处理
Web页面中经常碰到这类问题,就是客户端多次点击一个按钮或者链接,导致程序出现不可预知的麻烦. 客户就是上帝,他们也不是有意要给你的系统造成破坏,这么做的原因很大一部分是因为网络慢,点击一个操作之后, ...
- 对象的内置属性和js的对象之父Object()
js中对象有constructor,valueOf(),toString()等内置属性和方法; 创建一个空对象的方法: var o = {}; 或者 var o= new Object(); o.co ...
- for语句嵌套使用 实现9*9乘法表
这个实例主要考察对for循环语句的使用,出现递增规律的乘法表. 开发环境 开发工具:Microsoft Visual Studio2010 旗舰版 具体步骤 先是制作一个 ...
- Oracle 面试宝典 - General Questions
转自 http://www.orafaq.com/wiki/Interview_Questions Tell us about yourself/ your background. What are ...
- DEDECMS使用SQL命令批量替换语句
1.更改文章中的内容 update dede_addonarticle set body=replace(body,'原来的字符','替换后的字符') 2,替换文章标题 update dede_arc ...
- Linux系统上使用php获取apk信息
最近在做一个apk商城,需要在用户上传了apk之后系统自动读取apk信息(包名,版本号等),后台语言使用的是php,需要php去调用系统的aapt命令去读取apk信息,在Linux系统上安装aapt的 ...