HDU4020 Ads Proposal 排序+暴力打表

 先分类,并且根据click从高到低排序,进行编号,再根据编号进行二次排序,将相同编号的数据放一起。最后求和打表。

Ads Proposal

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1471    Accepted Submission(s): 518


Problem Description
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.

Input
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.

Output
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.

Sample Input
  
  
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

Sample Output
  
  
Case #1: 72 118 131 Case #2: 5801137622 5887132411 5887132411
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

#define MAXN 101000
#define MAXM 505000
#define max(a,b) (a>b?a:b)

struct data
{
	int u,c,n,l;
}da[MAXM];

int qu[MAXN];
__int64 a[MAXM];

int n,m,q,cases;

bool cmp1(data a,data b)
{
	if(a.u==b.u)
		return a.c>b.c;
	return a.u<b.u;
}

bool cmp2(data a,data b)
{
	return a.n<b.n;
}

void solve()
{
	int maxs=0;
	scanf("%d%d%d",&n,&m,&q);	
	for(int i=1;i<=m;i++)
		scanf("%d%d%d",&da[i].u,&da[i].c,&da[i].l);
	sort(da+1,da+1+m,cmp1);
	int k=1;
	for(int i=1;i<=m;)
	{
		int tag=1;
		while(da[i].u==k)
		{
			da[i].n=tag++;
			i++;
			if(i>m) break;		
		}
		maxs=max(tag-1,maxs);
		k++;
	}
	
	sort(da+1,da+1+m,cmp2);
	 k=1;
	a[0]=0;
	for(int i=1;i<=m;)
	{
		a[k]=a[k-1];
		while(da[i].n==k)
		{
			a[k]+=da[i++].l;
			if(i>m) break;
		}
		k++;	
	}
	printf("Case #%d:\n",cases);
	for(int k=1;k<=q;k++)
	{
		scanf("%d",&qu[k]);
		if(qu[k]>=maxs)
			printf("%I64d\n",a[maxs]);
		else
			printf("%I64d\n",a[qu[k]]);
	}
}


int main()
{
	int t;
	scanf("%d",&t);
	for(cases=1;cases<=t;cases++) 
		solve();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值