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。并在过程中增减伤害值,并记录最小伤害。

  1 //
  2 //by coolxxx
  3 //#include<bits/stdc++.h>
  4 #include<iostream>
  5 #include<algorithm>
  6 #include<string>
  7 #include<iomanip>
  8 #include<map>
  9 #include<stack>
 10 #include<queue>
 11 #include<set>
 12 #include<bitset>
 13 #include<memory.h>
 14 #include<time.h>
 15 #include<stdio.h>
 16 #include<stdlib.h>
 17 #include<string.h>
 18 //#include<stdbool.h>
 19 #include<math.h>
 20 #define min(a,b) ((a)<(b)?(a):(b))
 21 #define max(a,b) ((a)>(b)?(a):(b))
 22 #define abs(a) ((a)>0?(a):(-(a)))
 23 #define lowbit(a) (a&(-a))
 24 #define sqr(a) ((a)*(a))
 25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
 26 #define mem(a,b) memset(a,b,sizeof(a))
 27 #define eps (1e-10)
 28 #define J 10000
 29 #define mod 1000000007
 30 #define MAX 0x7f7f7f7f
 31 #define PI 3.14159265358979323
 32 #pragma comment(linker,"/STACK:1024000000,1024000000")
 33 #define N 20004
 34 using namespace std;
 35 typedef long long LL;
 36 double anss;
 37 LL aans;
 38 int cas,cass;
 39 int n,m,lll,ans;
 40 int Ta,Tb,X,sum;
 41 struct xxx
 42 {
 43     LL st,ct,et,d;
 44 }a[N],b[N];
 45 struct cmp1
 46 {
 47     bool operator ()(const int &aa,const int &bb)
 48     {
 49         return a[aa].st>a[bb].st;
 50     }
 51 };
 52 bool cmp(xxx aa,xxx bb)
 53 {
 54     return aa.et<bb.et;
 55 }
 56 int main()
 57 {
 58     #ifndef ONLINE_JUDGEW
 59 //    freopen("1.txt","r",stdin);
 60 //    freopen("2.txt","w",stdout);
 61     #endif
 62     int i,j,k;
 63     int x,y,z;
 64 //    init();
 65 //    for(scanf("%d",&cass);cass;cass--)
 66 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
 67 //    while(~scanf("%s",s))
 68 //    while(~scanf("%d",&n))
 69     while(~scanf("%d%d",&Ta,&Tb))
 70     {
 71         lll=0;ans=MAX;sum=0;
 72         scanf("%d%d%d",&X,&n,&m);
 73         for(i=1;i<=n;i++)
 74         {
 75             scanf("%d%d%d",&b[i].st,&b[i].ct,&b[i].d);
 76             b[i].et=b[i].st+b[i].ct;
 77             if(b[i].et>=X && b[i].et<=X+Tb)
 78             {
 79                 sum+=b[i].d;
 80                 a[++lll].st=b[i].et+b[i].ct;
 81                 j=Tb+X-a[lll].st;
 82                 j=j%(2*b[i].ct);
 83                 a[lll].et=Tb+X-j;
 84                 a[lll].d=b[i].d;
 85                 if(j>=b[i].ct)a[lll].et+=b[i].ct+b[i].ct;
 86                 if(a[lll].st+b[i].ct<X || a[lll].st>Tb+X)a[lll].et=a[lll].st;
 87             }
 88         }
 89         for(i=1;i<=m;i++)
 90         {
 91             scanf("%d%d%d",&b[i].st,&b[i].ct,&b[i].d);
 92             b[i].et=b[i].st+b[i].ct;
 93             sum+=b[i].d;
 94             a[++lll].st=b[i].et;
 95             j=Tb+X-a[lll].st;
 96             j=j%(2*b[i].ct);
 97             a[lll].et=Tb+X-j;
 98             a[lll].d=b[i].d;
 99             if(j>=b[i].ct)a[lll].et+=b[i].ct+b[i].ct;
100             if(a[lll].st+b[i].ct<X || a[lll].st>Tb+X)a[lll].et=a[lll].st;
101         }
102         sort(a+1,a+lll+1,cmp);
103         priority_queue<int,vector<int>,cmp1>q;
104
105         for(i=1;i<=lll;i++)
106         {
107             q.push(i);y=a[i].et;
108             sum-=a[i].d;
109             x=q.top();
110             while(y-a[x].st>Ta && !q.empty())
111             {
112                 sum+=a[x].d;
113                 q.pop();x=q.top();
114             }
115             ans=min(ans,sum);
116         }
117         printf("%d\n",ans);
118     }
119     return 0;
120 }
121 /*
122 //
123
124 //
125 */

时间: 2024-10-14 20:51:20

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 games. There are many famous War Chess games such as "Biography of Cao Cao", "Anecdotes of Wagang Mountain", etc. In this problem, let's c

hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

#1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people could not tolerate the pollution in the city any more, and started a long-lasting protest. Eventually, the municipal government made up its mind to deal w

hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0, 1, 2, -, n-1. He plans to spend m consecutive days(2 ≤ m ≤ n)in Beijing. Durin

hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】

https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 要求乘积最小只要求区间内最大值.最小值和绝对值小的数,再判断min,max正负就行了. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #define lson l,

hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

#1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a circle bouncing in a rectangle. As shown in the figure below, the rectangle is divided into N×M grids, and the circle fits exactly one grid. The bouncing

第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安站

 第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安赛区总结报告 报告人:田思明 队名:ACpioneer 队长:陈志阳,队员:顾振兴,田思明 西安区域赛告下帷幕,我和陈志阳,顾振兴组成的ACpioneer队最终获得了一块宝贵的铜牌.首先要感谢陈志阳和顾振兴两位杰出队友的努力训练和出色表现,我作为一个新人跟着他们学到了很多很多,也十分珍惜和他们在一起的训练,比赛时光,其次要感谢陈志老师,不辞辛劳陪我们5队和6队前往西安参加比赛,还要感谢集训队所有曾经帮过我们的所有队员们,记得cdy

第39届ACM国际大学生程序设计竞赛大陆地区赛站奖励方案

搬砖: 为了更好地吸引优秀选手参加第39届ACM国际大学生程序设计竞赛,全球赞助商的经费用于参赛队服和赛事的承办活动,中国赛区赞助商提供的经费用于优秀参赛队的奖励(包括奖金.奖牌.奖杯.获奖证书及奖品等), 竞赛命题,参赛手册,竞赛宣传方面的费用支出.每个赛区的具体奖励方式如下: 设冠军.亚军.季军三座奖杯,分别颁发奖金5000.3500.2000元人民币: 设15名金奖(包括冠.亚.季军)和30名银奖, 铜奖数量为参赛队数的30%: 获金奖的队(未获奖杯的队)每队颁发奖金1000元人民币; 获

《ACM国际大学生程序设计竞赛题解Ⅰ》——基础编程题

这个专栏开始介绍一些<ACM国际大学生程序设计竞赛题解>上的竞赛题目,读者可以配合zju的在线测评系统提交代码(今天zoj貌似崩了). 其实看书名也能看出来这本书的思路,就是一本题解书,简单暴力的通过题目的堆叠来提升解决编程问题的能力. 那么下面开始探索吧. zoj1037: BackgroundFor years, computer scientists have been trying to find efficient solutions to different computing p

2018 ACM 国际大学生程序设计竞赛上海大都会部分题解

题目链接 2018 ACM 国际大学生程序设计竞赛上海大都会 下午午休起床被同学叫去打比赛233 然后已经过了2.5h了 先挑过得多的做了 .... A题 rand x*n 次点,每次judge一个点位端点的共线向量数判断是否大于给定x 强行rand 500次 代码 #include<bits/stdc++.h> using namespace std; inline int read() { int x = 0,f = 1; char c = getchar(); while(c <