码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4020 Ads Proposal 离线操作

时间:2015-05-04 01:10:24      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

戳这里:HDU 4020

//为方便处理输入信息而对其进行 排序 预处理,算是经典的离线操作方法了

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 int T, N, M, Q;
 4 struct Ads
 5 {
 6     int U, C, L, Final_Rank;
 7 }ads[500010];
 8 long long res[500010];
 9 
10 bool cmp_1(Ads A, Ads B)
11 {
12     if(A.U != B.U) {
13         return A.U < B.U;
14     }
15     return A.C > B.C;
16 }
17 
18 bool cmp_2(Ads A, Ads B)
19 {
20     return A.Final_Rank < B.Final_Rank;
21 }
22 
23 int main()
24 {
25     int t;
26     scanf("%d", &T);
27     for(t = 1; t <= T; ++t) {
28         int i;
29         scanf("%d%d%d", &N, &M, &Q);
30         for(i = 1; i <= M; ++i) {
31             scanf("%d%d%d", &ads[i].U, &ads[i].C, &ads[i].L);
32         }
33         sort(ads + 1, ads + 1 + M, cmp_1);
34 
35 //        for(i = 1; i <= M; ++i) {
36 //            printf("Sorted %d %d %d\n", ads[i].U, ads[i].C, ads[i].L);
37 //        }
38 
39         int Rank = 1;
40         ads[1].Final_Rank = Rank;
41         for(i = 2; i <= M; ++i) {
42             if(ads[i].U == ads[i - 1].U) {
43                 ++Rank;
44                 ads[i].Final_Rank = Rank;
45             }
46             else {
47                 Rank = 1;
48                 ads[i].Final_Rank = Rank;
49             }
50         }
51         sort(ads + 1, ads + 1 + M, cmp_2);
52 
53 //        for(i = 1; i <= M; ++i) {
54 //            printf("Rank == %d %d %d %d\n", ads[i].Final_Rank, ads[i].U, ads[i].C, ads[i].L);
55 //        }
56 
57         Rank = 1;
58         res[Rank] = ads[1].L;
59         for(i = 2; i <= M; ++i) {
60             if(ads[i].Final_Rank == ads[i - 1].Final_Rank) {
61                 res[Rank] += ads[i].L;
62             }
63             else {
64                 ++Rank;
65                 res[Rank] = ads[i].L;
66                 res[Rank] += res[Rank - 1];
67             }
68         }
69         int Read_Rank;
70         printf("Case #%d:\n", t);
71         for(i = 1; i <= Q; ++i) {
72             scanf("%d", &Read_Rank);
73             printf("%I64d\n", Read_Rank <= Rank? res[Read_Rank]: res[Rank]);
74         }
75     }
76 }

 

HDU 4020 Ads Proposal 离线操作

标签:

原文地址:http://www.cnblogs.com/AC-Phoenix/p/4475098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!