首页 > ACM题库 > HDU-杭电 > HDU 3679-Jubilation[解题报告]HOJ
2014
11-30

HDU 3679-Jubilation[解题报告]HOJ

Jubilation

问题描述 :

One of the key elements to hold a successful programming contest is maximizing the overall satisfaction degree of all participating teams. Although a team’s satisfaction degree is influenced by many factors — for example, whether this competition is well-organized, and sometimes the weather condition of the place where the competition is held – but among those factors, what usually influences a team’s satisfaction degree most is the team’s performance in the contest.

Since the performance factor is a matter which the organizing committee cannot control, ask you to simply estimate the overall satisfaction degree of all teams. In particular, through years of experience, the committee asks you to calculate the satisfaction degree of a team using the following estimation steps:

1. If this team has performed in the contest at least as well as it had expected, its satisfaction degree is 3; otherwise
2. If this team’s performance is better than its last year’s performance, its satisfaction degree is 2; otherwise its satisfaction degree is 1.

(For the sake of simplicity, both the performance of a team and a team’s expectation are measured by its place on the rank list.)

This year’s and last year’s rank lists, along with the expectations of all teams are already given to you. (But the method which we used to find the expectations of the participating teams will remain a secret!) Can you calculate the total satisfaction degree of all teams by the above rules and the data you’ve been given?

输入:

There are multiple test cases in the input file. Each test case starts with one integer N (3<=N<=1000) on a single line, the number of teams participating in the contest.

The second line of every test case consists of N numbers in the range [1...N] , the i -th number representing the ID of team with i -th place in this year’s contest. Similarly, the third line of every test case describes the final rank list of last year’s contest. You can assume there will be no ties in the rank lists given to you.

The last line of every test case consists of N numbers in the range [1...N] , the i -th number representing the expectation of the i -th team this year. There’s a blank line between two successive test cases. A single line with N = 0 indicates the end of input file.

输出:

There are multiple test cases in the input file. Each test case starts with one integer N (3<=N<=1000) on a single line, the number of teams participating in the contest.

The second line of every test case consists of N numbers in the range [1...N] , the i -th number representing the ID of team with i -th place in this year’s contest. Similarly, the third line of every test case describes the final rank list of last year’s contest. You can assume there will be no ties in the rank lists given to you.

The last line of every test case consists of N numbers in the range [1...N] , the i -th number representing the expectation of the i -th team this year. There’s a blank line between two successive test cases. A single line with N = 0 indicates the end of input file.

样例输入:

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

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

0

样例输出:

Case 1: 12 
Case 2: 12

#include<stdio.h>
#include<string.h>

int n;

int a[4][2000];
int b[4][2000];

int main()
{
	int T = 0;
	while(1){
		++T;
		scanf("%d",&n);
		if(n == 0)
			break;
		for(int i = 1;i <= 3;++i)
			for(int j = 1;j <= n;++j)
				scanf("%d",&a[i][j]);
		for(int i = 1;i <= 2;++i)
			for(int j = 1;j <= n;++j)
				b[i][a[i][j]] = j;
		int sum = 0;
		for(int j = 1;j <= n;++j){
			if(a[3][j] >= b[1][j])
				sum += 3;
			else if(b[1][j] <= b[2][j])
				sum += 2;
			else
				sum += 1;
		}
		printf("Case %d: %d\n",T,sum);
	}
	return 0;
}

  1. 这道题目的核心一句话是:取还是不取。
    如果当前取,则index+1作为参数。如果当前不取,则任用index作为参数。

  2. 学算法中的数据结构学到一定程度会乐此不疲的,比如其中的2-3树,类似的红黑树,我甚至可以自己写个逻辑文件系统结构来。