T4

Title Description

John cows pampered childhood, they can not tolerate any dirty things in the bullpen. 
John found that if you want this group got a little older cows satisfaction, he had to hire some of them to clean the bullpen, John cows have N (1≤N≤10000) head are willing to earn some pocket money by cleaning bullpen money. 
Because cows littering will naturally anywhere in the cowshed in a certain period, they are required at this time, no matter what time must have at least one cow was cleaning. 
Needs cleaning period M seconds from the start of a day, the second end of the first E f0≤M≤E≤86399). Note that the second period is the time rather than a time point, that is, the total time required daily cleaning is E-M + I s.  
John has been a work plan they are willing to accept from each cow there: For a cow, she is willing in the day sleeping mat T1 ... T2-second period of work (where M <= T1 <= T2 <= E ), the required payment of $ S (0≤S≤500000). And the need to clean the description of the same period, if a cow is willing to work every day of the first period 10_20 seconds, that time her work is a total of 11 seconds instead of 10 seconds. Once John decided to hire a cow, you have to pay her full salary, not just let her work for some time, then press this time in the total time she was willing to work to determine a percentage of her salary . Now you help determine which cows John hired to keep the bullpen clean, of course, under the premise that allows cows satisfactory, John hopes to make the total cost as small as possible. 

Entry

Line 1: 3 positive integers N, M, E, separated by spaces.  
2 to N + 1: Line i + l given workplan row number i, cows, i.e. three space-separated positive integer Ti, T2, S. 

Export

Output An integer that represents the least cost to pay for John bullpen cleanup. If the clean-up work impossible, then output -1.

Sample input  Copy

3 0 4
0 2 3
3 4 2
0 0 1

Sample output Copy

5

prompt

John has three cows, cow between the 0th second to the second 4 needs to be cleaned. The first cow want to work in the first 0,1 seconds, for which she was paid $ 300 required. Rest and so on. John hired two cows before cleaning the bullpen, can spend only $ 500 to complete a full day of cleaning.

Ideas:

This problem seems at first glance, to see the minimum cost, the first reaction, network flows? DP? Or blue?

In a look at it this is not the shortest, but also almost naked, the time when the node, when the cost of wages cows, only to note is that i want i-1 and even a side at a cost of 0 would allow a cattle can not finish the work.

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <queue>
 6 using namespace std;
 7 const int maxn=1e6+10;
 8 const int inf=0x7fffffff;
 9 int head[maxn];
10 int tot=0;
11 bool vis[maxn];
12 int dis[maxn];
13 int n,m,d,k;
14 
15 queue<int >q;
16 int e;
17 struct node
18 {
19     int next;
20     int to;
21     long long len;
22 }way[maxn];
23 
24 int add(int x,int y,int w)
25 {
26     way[++tot].next=head[x];
27     way[tot].to=y;
28     way[tot].len=w;
29     head[x]=tot;
30 }
31 
32 int spfa()
33 {
34     q.push(m);
35     dis[m]=0;
36     vis[m]=true;
37     while(!q.empty())
38     {
39         int x=q.front();
40         q.pop();
41         vis[x]=false;
42         for(int i=head[x];i;i=way[i].next)
43         {
44             int to=way[i].to;
45             if(dis[x]+way[i].len<dis[to])
46             {
47                 dis[to]=dis[x]+way[i].len;
48                 if(!vis[to])
49                 {
50                     q.push(to);
51                     vis[to]=true;
52                 }
53             }
54         }
55     }
56 }
57 int main()
58 {
59     cin>>n>>m>>e;
60     memset(head,0,sizeof(head));
61     memset(vis,false,sizeof(vis));
62     e++;
63     for(int i=1;i<=n;i++)
64     {
65         int x;
66         int y;
67         int w;
68         cin>>x>>y>>w;
69         y++;
70         add(x,y,w);    
71     }
72     for(int i=m;i<=e-1;i++)
73     {
74         add(i+1,i,0);
75     }
76     for(int i=m;i<=e;i++)
77     {
78         dis[i]=inf;
79     }
80     spfa();
81     if(dis[e]==inf)
82     {
83         cout<<-1<<endl;
84     }
85     else
86     cout<<dis[e]<<endl;
87 }

 

 

 

Guess you like

Origin www.cnblogs.com/2529102757ab/p/10964016.html
T4
T4
T4
T4