#1391: countries time Limit: 1000ms single point limit: 1000ms memory limit: 256MB Description
There is antagonistic countries, country A and Country B. They is in a war, and keep launching missiles TOWARDS.
It's known that country A would launch N Missiles. The I-TH missile is launched at time Tai. It flies uniformly and take time taci from one country to the Other. It damage capability is Dai.
It's known that country B would launch M Missiles. The I-TH missile is 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 was activated, all missiles reaching the country would turn around and fly back at the same speed As they come.
At other time, the missiles reaching the country would do damages to the COUNTRY.
(Note that the defending system was still considered active at the exact moment it Fails)
Country B would activate its defending system at time X.
When was the best time for country A to activate its defending system? Please calculate the minimal damage country A would suffer.
Input
There is no more than-test Cases.
For each test case:
The first line contains integers TA and TB, indicating the lasting time of the defending system of the Countries.
The second line contains one integer X, indicating the time that country B would active its defending System.
The third line contains the integers N and M, indicating the number of missiles country A and country B would launch.
Then N lines FOLLOW. Each line contains three integers Tai, Taci and Dai, indicating the launching time, flying time and damage capability of T He 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 T He 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
Output
For each test case, output the minimal damage country A would suffer.
Tips
In the first case, country A should active it 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.
-
Sample input
-
2 221 01 1 104 532 21 2 101 5 71 3 20 4 8
-
Sample output
-
017
Topic links:
http://hihocoder.com/problemset/problem/1391
Main Topic:
A and b two countries Cross-fire missiles, each country has a defense system, in the time of the defense system can be launched to the national missile back (turn, the defense system can not open switch off).
Now known: Ta, Tb for a, B missile Defense can open the duration of X for the State B to open the missile defense system time (duration is [x,tb+x], including the end Point)
A to B launches n missiles, B launches M missiles to A. Each missile has 3 Values: launch time, flight time from A to B or B to a, damage Value.
A can now open the defense system at any time to find the minimum damage value for A.
Topic ideas:
"preprocessing + sorting + heap"
First preprocessing, to find out that each missile will not hit a need to open a state defense system time period [st,et], only a time period for the defense [y,y+ta] contains [st,et] then the missile will not hit A.
After preprocessing, each missile is sorted according to ET from small to large.
From 1 to n+m missiles, for the current missile, if need to be defended, then a defense system end time is et, then the opening time is Et-ta
Then remove the St<et-ta from the previously defensive missiles, saying they cannot be defended in the current Decision.
Can open an STL priority queue or heap record before the defensive missile serial number, according to St from small to large, each time the relatively smallest St and open time Et-ta. and increase the damage value in the process, and record the minimum damage.
1 //2 //by coolxxx3 //#include <bits/stdc++.h>4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <map>9#include <stack>Ten#include <queue> one#include <Set> a#include <bitset> -#include <memory.h> -#include <time.h> the#include <stdio.h> -#include <stdlib.h> -#include <string.h> - //#include <stdbool.h> +#include <math.h> - #defineMin (a) < (b) ( a):(b)) + #defineMax (a) (a) > (b)? ( a):(b)) a #defineABS (a) ((a) >0? ( A):(-(a))) at #defineLowbit (a) (a& (a)) - #defineSqr (a) ((a) * (a)) - #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b)) - #defineMem (a, b) memset (a,b,sizeof (a)) - #defineEPS (1e-10) - #defineJ 10000 in #defineMoD 1000000007 - #defineMAX 0x7f7f7f7f to #definePI 3.14159265358979323 + #pragmaComment (linker, "/stack:1024000000,1024000000") - #defineN 20004 the using namespacestd; *typedefLong LongLL; $ Doubleanss;Panax Notoginseng LL aans; - intcas,cass; the intn,m,lll,ans; + intta,tb,x,sum; a structXXX the { + LL st,ct,et,d; - }a[n],b[n]; $ structCMP1 $ { - BOOL operator()(Const int&aa,Const int&Bb) - { the returnA[aa].st>a[bb].st; - }Wuyi }; the BOOLcmp (xxx aa,xxx bb) - { wu returnaa.et<bb.et; - } about intMain () $ { - #ifndef Online_judgew - //freopen ("1.txt", "r", stdin); - //freopen ("2.txt", "w", stdout); a #endif + inti,j,k; the intx, y, z - //Init (); $ //for (scanf ("%d", &cass); cass;cass--) the //for (scanf ("%d", &cas), cass=1;cass<=cas;cass++) the //while (~scanf ("%s", S)) the //while (~scanf ("%d", &N)) the while(~SCANF ("%d%d",&ta,&Tb)) - { inLll=0; ans=max;sum=0; thescanf"%d%d%d",&x,&n,&m); the for(i=1; i<=n;i++) about { thescanf"%d%d%d",&b[i].st,&b[i].ct,&b[i].d); theb[i].et=b[i].st+b[i].ct; the if(b[i].et>=x && b[i].et<=x+Tb) + { -sum+=b[i].d; thea[++lll].st=b[i].et+b[i].ct;Bayij=tb+x-a[lll].st; thej=j% (2*b[i].ct); thea[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; the if(a[lll].st+b[i].ct<x | | a[lll].st>tb+x) a[lll].et=a[lll].st; the } the } the for(i=1; i<=m;i++) - { thescanf"%d%d%d",&b[i].st,&b[i].ct,&b[i].d); theb[i].et=b[i].st+b[i].ct; thesum+=b[i].d;94a[++lll].st=b[i].et; thej=tb+x-a[lll].st; thej=j% (2*b[i].ct); thea[lll].et=tb+x-j;98A[lll].d=b[i].d; about 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;101 }102Sort (a +1, a+lll+1, cmp);103priority_queue<int,vector<int>,cmp1>q;104 the for(i=1; i<=lll;i++)106 {107Q.push (i); y=a[i].et;108sum-=a[i].d;109x=q.top (); the while(y-a[x].st>ta &&!)Q.empty ())111 { thesum+=a[x].d;113Q.pop (); x=q.top (); the } theans=min (ans,sum); the }117printf"%d\n", ans);118 }119 return 0; - }121 /*122 //123 124 // the */
View Code
Hihocoder 1391 Countries "preprocessing + sorting + heap" (ACM-ICPC International College Student Program Design competition Beijing (2016) online Game)