首页 > 其他 > 详细

Huge Mission

时间:2014-02-25 00:14:00      阅读:498      评论:0      收藏:0      [点我收藏+]

 

                                                             Huge Mission

Problem Description

 

Oaiei is busy working with his graduation design recently. If he can not complete it before the end of the month, and he can not graduate! He will be very sad with that, and he needs your help. There are 24 hours a day, oaiei has different efficiency in different time periods, such as from 0 o’clock to 8 o‘clock his working efficiency is one unit per hour, 8 o‘clock to 12 o‘clock his working efficiency is ten units per hour, from 12 o‘clock to 20 o‘clock his working efficiency is eight units per hour, from 20 o‘clock to 24 o‘clock his working efficiency is 5 units per hour. Given you oaiei’s working efficiency in M periods of time and the total time N he has, can you help him calculate his greatest working efficiency in time N.

 

 Input

 

There are multiple tests. In each test the first line has two integer N (2 <= N <= 50000) and M (1 <= M <= 500000), N is the length of oaiei’s working hours; M is the number of periods of time. The following M lines, each line has three integer S, T, P (S < T, 0 < P <= 200), represent in the period of time from S to T oaiei’s working efficiency is P units per hour. If we do not give oaiei’s working efficiency in some periods of time, his working efficiency is zero. Oaiei can choose part of the most effective periods of time to replace the less effective periods of time. For example, from 5 o’clock to 10 o’clock his working efficiency is three units per hour and from 1 o’clock to 7 o’clock his working efficiency is five units per hour, he can choose working with five units per hour from 1 o’clocks to 7 o’clock and working with three units per hour from 7 o’clock to 10 o’clock.

 

bubuko.com,布布扣 Output

 

You should output an integer A, which is oaiei’s greatest working efficiency in the period of time from 0 to N.

 

bubuko.com,布布扣 Sample Input

 

24 4
0 8 1
8 12 10
12 20 8
20 24 5
4 3
0 3 1
1 2 2
2 4 5
10 10
8 9 15
1 7 5
5 10 3
0 7 6
5 8 2
3 7 3
2 9 12
7 8 14
6 7 2
5 6 16

 

bubuko.com,布布扣 Sample Output

 

132
13
108

 

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <math.h>
 5 #include <algorithm>
 6 #include <stdlib.h>
 7 #include <map>
 8 #define ll long long
 9 using namespace std;
10 typedef struct abcd
11 {
12     int x,y,p;
13 } abcd;
14 abcd a[500010];
15 int  b[50010<<4];
16 bool cmp(abcd x,abcd y)
17 {
18     return x.p<y.p;
19 }
20 void build(int l,int r,int t)
21 {
22     if(l==r)
23     {
24         b[t]=1;
25         return ;
26     }
27     int m=(l+r)>>1;
28     build(l,m,t<<1);
29     build(m+1,r,t<<1|1);
30     b[t]=b[t<<1]+b[t<<1|1];
31 }
32 void update(int x,int y,int l,int r,int t)
33 {
34     if(b[t]==0)return;
35     if(x<=l&&y>=r)
36     {
37         b[t]=0;
38         return;
39     }
40     int m=(l+r)>>1;
41     if(x<=m)update(x,y,l,m,t<<1);
42     if(y>m)update(x,y,m+1,r,t<<1|1);
43     b[t]=b[t<<1]+b[t<<1|1];
44 }
45 int query(int x,int y,int l,int r,int t)
46 {
47     if(b[t]==0)return 0;
48     if(x<=l&&y>=r)
49     {
50         return b[t];
51     }
52     int m=(l+r)>>1;
53     int sum=0;
54     if(x<=m)sum+=query(x,y,l,m,t<<1);
55     if(y>m)sum+=query(x,y,m+1,r,t<<1|1);
56     return sum;
57 }
58 int main()
59 {
60     int n,m,i,j;
61     while(cin>>n>>m)
62     {
63         build(1,n,1);
64         for(i=0; i<m; i++)
65         {
66             scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].p);
67             a[i].x++;
68         }
69         sort(a,a+m,cmp);
70         int sum=0;
71         for(i=m-1; i>=0; i--)
72         {
73             int r=query(a[i].x,a[i].y,1,n,1);
74             update(a[i].x,a[i].y,1,n,1);
75             sum+=r*a[i].p;
76         }
77         cout<<sum<<endl;
78     }
79 }
View Code

 

 

 

Huge Mission

原文:http://www.cnblogs.com/ERKE/p/3563884.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!