首页 > ACM题库 > HDU-杭电 > HDU 1704 Rank[解题报告] C++
2013
12-21

HDU 1704 Rank[解题报告] C++

Rank

问题描述 :

there are N ACMers in HDU team.
ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellent ACMers to attend the contest. There have been M matches since the last few days(No two ACMers will meet each other at two matches, means between two ACMers there will be at most one match). lcy also asks"Who is the winner between A and B?" But sometimes you can’t answer lcy’s query, for example, there are 3 people, named A, B, C.and 1 match was held between A and B, in the match A is the winner, then if lcy asks "Who is the winner between A and B", of course you can answer "A", but if lcy ask "Who is the winner between A and C", you can’t tell him the answer.
As lcy’s assistant, you want to know how many queries at most you can’t tell lcy(ask A B, and ask B A is the same; and lcy won’t ask the same question twice).

输入:

The input contains multiple test cases.
The first line has one integer,represent the number of test cases.
Each case first contains two integers N and M(N , M <= 500), N is the number of ACMers in HDU team, and M is the number of matchs have been held.The following M lines, each line means a match and it contains two integers A and B, means A wins the match between A and B.And we define that if A wins B, and B wins C, then A wins C.

输出:

For each test case, output a integer which represent the max possible number of queries that you can’t tell lcy.

样例输入:

3
3 3
1 2
1 3
2 3
3 2
1 2
2 3
4 2
1 2
3 4

样例输出:

0
0
4

Hint
in the case3, if lcy ask (1 3 or 3 1) (1 4 or 4 1) (2 3 or 3 2) (2 4 or 4 2), then you can't tell him who is the winner.

很简单的一道题,让我WA了n次,没想到给的数据还可以是不安时间先后的,搞得都没兴趣了,代码很乱,懒得改了

t[i].cuo[j]         表示i同学j题的错误提交次数    若为-1则表示已经提交成功

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct team
{
	int no,time,sol,cuo[25];
}t[1010];
struct ti
{
	int ttno,tpno,tti,tju;
}jiao[1010];
int cmp(const void *a,const void *b)
{
	struct team *c=(struct team *)a,*d=(struct team *)b;
	if(c->sol!=d->sol)
		return d->sol-c->sol;
	else if(c->time!=d->time)
		return c->time-d->time;
	else return c->no-d->no;
}
int cmpp(const void *a,const void *b)
{
	struct ti *c=(struct ti *)a,*d=(struct ti *)b;
	return c->tti-d->tti;
}
int main()
{
	int c,n,i,tno,pno,ti,ju;
	while(scanf("%d%d",&c,&n)!=EOF)
	{	
		memset(t,0,sizeof(t));
		for(i=0;i<c;i++)
			t[i].no=i;
		for(i=0;i<n;i++)
			scanf("%d%d%d%d",&jiao[i].ttno,&jiao[i].tpno,&jiao[i].tti,&jiao[i].tju);
		qsort(jiao,n,sizeof(jiao[0]),cmpp);
		for(i=0;i<n;i++)
		{
			tno=jiao[i].ttno;
			pno=jiao[i].tpno;
			ti=jiao[i].tti;
			ju=jiao[i].tju;
			if(ju)
			{
				if(t[tno-1].cuo[pno]>=0)
				{
					t[tno-1].sol++;
					t[tno-1].time+=ti+t[tno-1].cuo[pno]*20*60;
					t[tno-1].cuo[pno]=-1;
				}
	
			}
			else
			{
				t[tno-1].cuo[pno]++;
			}
		}
		qsort(t,c,sizeof(t[0]),cmp);
		printf("%d",t[0].no+1);
		for(i=1;i<c;i++)
				printf(" %d",t[i].no+1);
		printf("\n");
	}
	return 0;
}

解题报告转自:http://blog.csdn.net/qq172108805/article/details/6628338


  1. 有一点问题。。后面动态规划的程序中
    int dp[n+1][W+1];
    会报错 提示表达式必须含有常量值。该怎么修改呢。。