Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 1801 | Accepted: 648 |
Description
The situation is like this. The slides all have numbers written on them according to their order in the talk. Since the slides lie on each other and are transparent, one cannot see on which slide each number is written.
Well, one cannot see on which slide a number is written, but one may deduce which numbers are written on which slides. If we label the slides which characters A, B, C, ... as in the figure above, it is obvious that D has number 3, B has number 1, C number 2 and A number 4.
Your task, should you choose to accept it, is to write a program that automates this process.
Input
This is followed by n lines containing two integers each, the x- and y-coordinates of the n numbers printed on the slides. The first coordinate pair will be for number 1, the next pair for 2, etc. No number will lie on a slide boundary.
The input is terminated by a heap description starting with n = 0, which should not be processed.
Output
If no matchings can be determined from the input, just print the word none on a line by itself.
Output a blank line after each test case.
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 2 0 2 0 2 0 2 0 2 1 1 1 1 0
Sample Output
Heap 1 (A,4) (B,1) (C,2) (D,3) Heap 2 none
Source
Source Code
Problem: 1486 | User: bingshen | |
Memory: 176K | Time: 0MS | |
Language: C++ | Result: Accepted |
- Source Code
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; struct Rect { int minx; int maxx; int miny; int maxy; }; struct Point { int x; int y; }; Rect rect[200]; Point point[200]; bool map[200][200]; int link[200]; bool used[200]; int n; bool judge(Rect a,Point b) { if(a.minx<=b.x&&b.x<=a.maxx&&a.miny<=b.y&&b.y<=a.maxy) return true; else return false; } bool dfs(int v) { int i; for(i=1;i<=n;i++) { if(!used[i]&&map[v][i]) { used[i]=true; if(link[i]==-1||dfs(link[i])) { link[i]=v; return true; } } } return false; } bool mark() { int i; memset(link,-1,sizeof(link)); for(i=1;i<=n;i++) { memset(used,0,sizeof(used)); if(!dfs(i)) return false; } return true; } int main() { int i,j,t=1,k; while(scanf("%d",&n)!=EOF) { if(n==0) break; memset(map,0,sizeof(map)); for(i=1;i<=n;i++) scanf("%d%d%d%d",&rect[i].minx,&rect[i].maxx,&rect[i].miny,&rect[i].maxy); for(i=1;i<=n;i++) scanf("%d%d",&point[i].x,&point[i].y); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { if(judge(rect[i],point[j])) map[i][j]=true; } bool first=false; printf("Heap %d/n",t++); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { if(map[i][j]==true) { map[i][j]=false; if(!mark()) { if(!first) { printf("(%c,%d)",i+'A'-1,j); first=true; } else printf(" (%c,%d)",i+'A'-1,j); for(k=1;k<=n;k++) { if(k!=i) map[k][j]=false; if(k!=j) map[i][k]=false; } } map[i][j]=true; } } if(!first) printf("none/n/n"); else printf("/n/n"); } return 0; }