hdu 4020 很好的set和结构体的结合运用 很帅的一个题啊
2012-12-10 19:37
218 查看
Ads Proposal
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 1537 Accepted Submission(s): 534
[align=left]Problem Description[/align]
There are N customers set their M different advertisements on Baidu. Each advertisement is owned by single customer. The ads system of Baidu records the number of clicks of each advertisement this year. The proposal system wants to
analysis the advertisements about the relativity of the description length and the number of clicks of the advertisements. During the analysis, it is very important to do such a query to ask the total length of the advertisements with top k clicking times
for each customer. You may assume the number of clicks of all advertisements are distinct.
Your task is to help Baidu to design this little toolkit.
[align=left]Input[/align]
The input consist multiple test cases. The number of test cases is given in the first line of the input.
For each test case, the first line contains three integers N, M and Q, denoting the number customer, the number of advertisement instances and the number of queries. (N <= 100000, M <= 500000, Q <= 100000)
Then M lines follow, each line contains three numbers, U, C and L, indicating the owner of this advertisement, the clicks for this advertisement and the length. (1 <= U <= N, 0 <= C, L <= 1000000000)
Finally Q lines come. Each line contains only one integer k, representing the query for top k clicking advertisements for each customer.
[align=left]Output[/align]
For each test case, output Q lines, each line contains only one integer, denoting the sum of total length of the top k number of clicks for each customer.
[align=left]Sample Input[/align]
2
2 4 3
1 12 13
2 23 41
1 21 46
1 22 31
1
2
3
6 15 3
5 2677139 731358928
2 347112028 239095183
6 27407970 85994789
6 767687908 734935764
6 255454855 110193353
3 39860954 813158671
5 617524049 55413590
3 338773814 7907652
6 810348880 736644178
2 777664288 63811422
6 590330120 616490361
5 552407488 136492190
1 416295130 448298060
5 811513162 232437061
4 43273262 874901209
4
9
13
[align=left]Sample Output[/align]
Case #1:
72
118
131
Case #2:
5801137622
5887132411
5887132411
[align=left]Source[/align]
The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup
[align=left]Recommend[/align]
lcy
题意描述:有n个顾客,m个广告,每个顾客可以有多个广告,每个广告有一个点击量和长度,现在要求每个顾客前k个访问量的长度总和的总和
思路 :
不要对每个k去求 然后相加 应该在程序中打表 找出所有的 直接对应输出
#include<stdio.h> #include<string.h> #include<set> using namespace std; #define ll __int64 struct haha { ll c; ll l; bool operator<(const haha &x) const //由于set只能按一个元素排序 结构体有多个元素必须指定一个元素排序 { return c>x.c;//从大到小 } }a; set<haha>ss[100000+10]; set<haha>::iterator it; int getval()//快速输入法 { int ret(0); char c; while((c=getchar())==' '||c=='\n'||c=='\r'); ret=c-'0'; while((c=getchar())!=' '&&c!='\n'&&c!='\r') ret=ret*10+c-'0'; return ret; } ll ans[500100]; int main() { int i,cas,n,m,q,c_num=0,j; // scanf("%d",&cas); cas=getval(); while(cas--) { // scanf("%d %d %d",&n,&m,&q);//由于数据量极大 所以用上面那种输入方式 注意当你超时的时候一定要想起用这个 n=getval(); m=getval(); q=getval(); for(i=0;i<=n;i++) ss[i].clear();//靠!!!!!这里少了个=号 一个劲的错 哎 小心使得万年船啊 for(i=0;i<m;i++) { int user; user=getval(); a.c=(ll)getval(); a.l=(ll)getval(); // scanf("%d %I64d %I64d",&user,&a.c,&a.l); ss[user].insert(a); } memset(ans,0,sizeof(ans)); for(i=1;i<=n;i++) { int cnt=1; for(it=ss[i].begin();it!=ss[i].end();it++) { ans[cnt]+=(*it).l; cnt++; } } for(i=1;i<=m;i++) { ans[i]+=ans[i-1]; } printf("Case #%d:\n",++c_num); for(i=0;i<q;i++) { int k; k=getval(); if(k>m) k=m; printf("%I64d\n",ans[k]); } } return 0; }
相关文章推荐
- 1.2.26 Set.toArray方法——用Set集合中的所有对象创建一个数组(很好)
- Android EditText.setError() - 会弹出一个popupwindow,效果很好
- Android EditText.setError() - 会弹出一个popupwindow,效果很好
- hdu 4022 map的一对多实现 map和set的结合应用
- hdu 4020(一个水题)
- 利用sleep函数(Linux平台)结合结构体,编写一个模拟时钟
- HDU 5058 So easy(STL 集合set的运用)
- 正则语言引擎:一个简单LEX和YACC结合运用的实例
- hdu 4941 Magical Forest(STL map & 结构体运用)
- hdu 4020 hash的精妙运用
- map容器的使用 加上一个map与set综合运用的例子
- hdu 5249 KPI set与其迭代器的运用
- 一个很好的关于多态的题目
- hdu 1841 KMP运用
- 一个很好的书籍下载网站
- 怎么实现ZBrush与数位板雕刻模型的结合运用
- hdu 3006 The Number of set 状压dfs
- HDU 七夕节(求一个数的因子和)
- 一个实例说明java中的list,set,map三者区别
- 递归结合左式堆的一个具体说明!