[Deduplication? ] [Simulation] Professor confused

Preface:

l t h lth Gangster taught general idea, and then I looked for a moment his mark, then knocked on the even A.
l Y f drugs big brother even topological sorting of A.


topic:

Professor Chen is a world-renowned professors, many units are scrambling invited him to speak, Professor Chan will do a very important speech this afternoon. Due to the large Professor Chen older, little things unimportant for a bit confused this morning to do his own speech to use slides casually stacked together. Therefore, before the lecture he had to sort out these slides. Due to time constraints, he hoped to complete it as simple as possible. This is the case, Professor Chen to use the speech altogether slides n (n <= 26), the n-slide presentation to be used in the order has been digitally 1,2, ..., n in the above compiled on the number . Because the slide is transparent, so all of a sudden we can not see each number corresponding to the slide.
Now we use capital letters A, B, C, ... slide again compiled on the order number, your task is to write a program to slide numbered and lettered correspondence, apparently this correspondence should be unique; if circumstances arise or more corresponding numbers and letters correspond to certain numbers up, we say correspondence can not be achieved.


Input:

The first line is only a number n, the n-slide, the next row includes n row four integer Xmin, Xmax, Ymin, Ymax (separated by spaces between integer), the coordinates of the slide, which n slides order they appear in the input file are sequentially numbered from the front to the rear of a, B, C, ... and then the next n rows of n sequentially numbered coordinates X, Y, is clearly outside the slide It is not numbered.


Output:

If the correspondence can be realized, your output file should comprise n rows, each act a letter and a number, in the middle by a space apart, and each row in ascending order letter, note letters outputted capitalized and the top grid; conversely, if the correspondence can not be achieved, in the first line of the file to the top grid output None. End of the line the first line and no extra spaces.


Sample input:

4 
6 22 10 20
4 18 6 16
8 20 2 18
10 24 4 8
9 15
19 17
11 7
21 11

Sample output:

A  4
B  1
C  2
D  3

Ideas:

It is made up of several overlapping slide together, so you come to the corresponding draw a map so we understand how the emotional
Here Insert Picture Description
look at the slides ABC
A 2 has 1
B has 3 2
C in 3
and C slides only a 3
so 3 out ban
and then a second time cycle
a, there are still 12
but!
B 3 out ban is
so B is 2
again cycling
since the ban was 2
so A is 1
so that
A 1
B 2
C 3
we specifically how to do it, is to turn to the only, then put out a ban one up, and then determine there is no ban do not continue to be circulating on the line.


C O d e Code

#include<cstdio>
#include<iostream>
using namespace std;
int sum,maxn[1000],answer[1000],Xmin[1000],Xmax[1000],Ymin[1000],Ymax[1000],n,x,y,f[1000][1000];
bool check;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d%d%d%d",&Xmin[i],&Xmax[i],&Ymin[i],&Ymax[i]);//输入
	for(int i=1;i<=n;i++)
	{ 
	  scanf("%d%d",&x,&y);
	  for(int j=1;j<=n;j++)
	  if(x>=Xmin[j]&&y>=Ymin[j]&&x<=Xmax[j]&&y<=Ymax[j])//幻灯片的边界
	  f[i][++maxn[i]]=j;//判断是不是对应
	} 
	sum=n;
	while(sum)
	{
		for(int i=1;i<=n;i++)
		{
			if(maxn[i]==1)
			{
				check=true;//判断是否存在唯一性
				answer['A'+f[i][1]]=i;//计算
				for(int j=1;j<=n;j++)
				for(int k=1;k<=maxn[j];k++)
				if(f[j][k]==f[i][1]&&j!=i){swap(f[j][k],f[j][maxn[j]]);f[j][maxn[j]]=0;maxn[j]--;}
			   sum--;f[i][1]=1;maxn[i]--;//ban掉
			}
			
		}
		if(check)check=false;
		else {printf("None");return 0;}
	} 
	for(int i=1;i<=n;i++)
	{
		printf("%c %d",64+i,answer['A'+i]);//输出
		printf("\n");
	}
	return 0;
} 

Guess you like

Origin blog.csdn.net/hunkwu/article/details/91874018