锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
Description
Input
Output
Sample Input
Sample Output
Description Input Output Sample Input Sample Output
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.
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.
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.
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
Heap 1
(A,4) (B,1) (C,2) (D,3)
Heap 2
none
棰樻剰錛氭湁緙栧彿鐨勫夠鐏墖鏄忔槑鐨勶紝鍙犲湪涓璧風殑鏃跺欙紝闄や簡娌¤瑕嗙洊鐨勭紪鍙鳳紝鍏朵粬鐨勭紪鍙瘋澶氬紶騫葷伅鐗囪鐩栨椂灝卞垎涓嶆竻鍝釜緙栧彿鏄摢寮犵殑銆?br>浣嗚兘閫氳繃紜畾鐨勫夠鐏墖鐨勭紪鍙鳳紙緙栧彿鍙涓寮犲夠鐏墖瑕嗙洊錛岃繖涓紪鍙峰氨鏄騫葷伅鐗囩殑錛夋潵鐢ㄦ帓闄ゆ硶紜畾鍏朵粬騫葷伅鐗囩殑緙栧彿銆?br>姹傦細鏄惁鑳界‘瀹氭墍鏈夊夠鐏墖鐨勭紪鍙楓傚鏋滃彲浠ワ紝瀵規瘡寮犲夠鐏墖錛屽垽鏂繖涓紪鍙鋒槸鍚︽槸鍞竴鐨勩傚鍞竴緙栧彿騫葷伅鐗囪緭鍑虹紪鍙楓?br>鍒嗘瀽錛氳繖涓洿鎺ユ槸姣旇緝鏄庢樉鐨勪簩鍒嗗浘鏈澶у尮閰嶃傞鍏堣偗瀹氭槸閫夊彇鍞竴紜畾鐨勫夠鐏墖涓嶇敤錛屾帴涓嬫潵灝辨槸浜ゅ弶璺緞姹傚彲澧炲厜璺殑浜嬩簡銆傛暣涓繃紼嬪氨鏄寛鐗欏埄綆楁硶銆?br>姹傚嚭鍖歸厤鏂規M錛屽M涓瘡嬈″垹闄や竴涓竟錛屽啀嬈¢氳繃璇ヨ竟鐨勪竴鐐圭湅鐪嬫槸鍚︽湁鍙鍏夎礬錛屾湁鍒欎細鍐嶆杈懼埌鏈澶у尮閰嶏紝榪欒鏄庤緙栧彿瀵瑰簲鐨勫彲閫夌煩褰笉鍞竴銆?br>
#define maxn 1000
using namespace std;
struct T
{
int x1, x2, y1, y2;
}reg[maxn];
int mat[maxn][maxn], hash[maxn], pre[maxn], path[maxn];
int n;
int more(int u)
{
int i;
for (i = 0; i < n; i++)
{
if (hash[i] == 0 && mat[u][i])
{
hash[i] = 1;
if (pre[i] == -1 || more(pre[i]))
{
pre[i] = u;
return 1;
}
}
}
return 0;
}
int eft()
{
int i, j, num;
for (i = 0; i < n; i++) pre[i] = -1;
for (i = 0, num = 0; i < n; i++)
{
for (j = 0; j < n; j++) hash[j] = 0;
if (more(i))
{
num++;
}
}
return num;
}
int main()
{
int i, j, x1, x2, y1, y2, x, y, num, sign, ca = 0, m;
while (scanf("%d", &n), n)
{
ca++;
for (i = 0; i < n; i++)
{
scanf("%d%d%d%d", ®[i].x1, ®[i].x2, ®[i].y1, ®[i].y2);
}
for (i = 0; i < n; i++)
{
scanf("%d%d", &x, &y);
for (j = 0; j < n; j++)//緙栧彿琚夠鐏墖涓婅鐩栫殑錛岀紪鍙瘋窡鍏惰繛杈癸紝琛ㄧず璇ョ紪鍙峰彲鑳藉湪璇ュ夠鐏墖涓?/span>
{
if (x > reg[j].x1 && x < reg[j].x2 && y > reg[j].y1 && y < reg[j].y2)
{
mat[i][j] = 1;
}
else
{
mat[i][j] = 0;
}
}
}
num = eft();
sign = 0;
printf("Heap %d\n", ca);
if (num == n)//鑳芥壘鍒頒竴縐嶆柟妗堣姣忎釜緙栧彿瀵瑰簲涓涓夠鐏墖
{
for (i = 0; i < n; i++)
{
path[i] = pre[i];
}
for (i = 0; i < n; i++)
{
mat[path[i]][i] = 0;//鍒犺竟
if (eft() == num)//濡傛灉鑳藉啀嬈¤揪鍒版渶澶у尮閰峂錛屽垯緙栧彿璺熷夠鐏墖涓嶆槸鍞竴鐨?/span>
{
continue;
}
else
{
if (sign)
{
printf(" ");
}
printf("(%c,%d)", 'A' + i, path[i] + 1);//鍚﹀垯錛岃緭鍑哄敮涓瀵瑰簲鐨勫夠鐏墖璺熺紪鍙楓?/span>
sign = 1;
}
mat[path[i]][i] = 1;
}
}
if (!sign)
{
printf("none");
}
printf("\n\n");
}
return 0;
}
]]>
P N
Count1 Student1 1 Student1 2 ... Student1 Count1
Count2 Student2 1 Student2 2 ... Student2 Count2
...
CountP StudentP 1 StudentP 2 ... StudentP CountP
The first line in each data set contains two positive integers
separated by one blank: P (1 <= P <= 100) - the number of courses
and N (1 <= N <= 300) - the number of students. The next P lines
describe in sequence of the courses 錕絝rom course 1 to course P, each
line describing a course. The description of course i is a line that
starts with an integer Count i (0 <= Count i <= N) representing
the number of students visiting course i. Next, after a blank, you鎶
find the Count i students, visiting the course, each two consecutive
separated by one blank. Students are numbered with the positive integers
from 1 to N.
There are no blank lines between consecutive sets of data. Input data are correct.
2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1YES
NO
棰樻剰錛氱粰鍑鴻紼嬫暟璺熷鐢熸暟錛屼互鍙婅紼嬪搴旂殑瀛︾敓銆?br>姹傛槸鍚﹀瓨鍦ㄨ鎵鏈夎紼嬭窡涓嶅悓鐨勫鐢熷搴斻?br>
#include <stdlib.h>
#define maxn 310
int map[maxn][maxn], hash[maxn], pre[maxn], gn, gm;
//gn宸﹁竟x鐨勭偣鏁幫紝gm鍙寵竟y鐨勭偣鏁?nbsp;
//pre鏄彸杈硅妭鐐硅繛鎺涓殑鑺傜偣
//hash鏄彸杈圭殑鑺傜偣鏈夋病鏈夎璁塊棶榪?nbsp;
void set()
{
for (int i = 1; i <= gn; i++)
{
for (int j = 1; j <= gm; j++)
{
map[i][j] = 0;
}
}
for (int j = 1; j <= gm; j++)
{
pre[j] = -1;
}
}
int han(int u)
{
for (int v = 1; v <= gm; v++)
{
if (hash[v] == 0 && map[u][v])//杈瑰瓨鍦ㄤ笖鍙寵妭鐐規病琚闂繃
{
hash[v] = 1;
if (pre[v] == -1 || han(pre[v]))//v榪樻病鏈夊墠緗妭鐐規垨v鐨勫墠緗妭鐐瑰瓨鍦ㄥ騫胯礬
{
pre[v] = u;//璁懼畾v鐨勫墠緗妭鐐?nbsp;
return 1;
}
}
}
return 0;
}
int main()
{
int t, i, j, m, u, v, num;
scanf("%d", &t);
while (t--)
{
scanf("%d%d", &gn, &gm);
set();
for (i = 1; i <= gn; i++)
{
scanf("%d", &m);
while (m--)
{
scanf("%d", &v);
map[i][v] = 1;
}
}
for (i = 1, num = 0; i <= gn; i++)
{
for (j = 1; j <= gm; j++)
{
hash[j] = 0;
}
if (han(i))
{
num++;
}
}
if (num == gn)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
system("pause");
return 0;
}
]]>