Los Columbia Valley T2691 barrel problem - send a barrel

Ok...

 

Topic link: https: //www.luogu.org/problem/T2691

 

This question is a little greedy thoughts and ideas ... and it is subject to the upside (seems this idea has been very common ...

 

For the first chestnuts:

Elicit ideas: by the end of the time sooner or later sort, because there is no limit on how early, but at the latest to time there is a limit. The back time, look backwards time axis, t is first initialized to max (b [i]), then enumerated again, if the current is greater than t b [i], the time t can not reach it, so to move t to b [i]. And t is time consuming to subtract a [i].

The initial value to the last time, to push forward, if room in front of a later time than the time limit for the node (e.g., F) minus the delivery time (EF) night, then put the previous period of time delivery by subtracting, because the two coincide (GH and EF) period, in practice impossible to simultaneously send two meals, then the most compact arrangement is to superimposing next forward, then it becomes F t (abscissa) minus the length EF and GH to obtain a new abscissa, and then move completion time limit, and a front point (B) compared to see which more later.

If a later time node (eg F) minus the delivery time (EF) in front of a room later than the time limit, it means the minimum time limit to advance to the current point of time limit, as long as arrangements properly, from the current after the time limit point in time will not have any impact on the first time! So we put t advance to the current point of time constraints, continue to push forward on the line.

AC Code:

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 //时间倒流 
 5 using namespace std;
 6 
 7 const int maxn = 1e6 + 5;
 8 
 9 int n;
10 struct node{
11     int a, b;
12 } e[maxn];
13 
14 inline bool cmp(node x, node y){
15     return x.b > y.b;
16 }
17 
18 int main(){
19     scanf("%d", &n);
20     for(int i = 1; i <= n; i++)
21         scanf("%d%d", &e[i].a, &e[i].b);
22     sort(e + 1, e + 1 + n, cmp);
23     int t = e[1].b;
24     for(int i = 1; i <= n; i++){
25         if(t > e[i].b) t = e[i].b;
26         t -= e[i].a;
27     }
28     printf("%d\n", t);
29     return 0;
30 } 
AC Code

 

Guess you like

Origin www.cnblogs.com/New-ljx/p/11246843.html