标签:
戳这里: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 }
标签:
原文地址:http://www.cnblogs.com/AC-Phoenix/p/4475098.html