用户ID: 密码: 验证:

登 录

注 册 取回密码

中山教育

中山国际网

中国教育在线

时代财富科技公司 FortuneAge Technology Co., Ltd. 校园博客客服网站(新)

我的资料

Mpq

博客信息

积分:988
等级:4级 lv 4
日志总数:231
发表评论总数:18 ( 查看)
获得评论总数:21
发表留言总数:0
所属学校:三鑫
收藏本站:

最新公告

欢迎光临我的博客!

最新相册

我的日历

最新评论

--游客
好文好文,是您的手笔?如果是您的文章,如果您愿意和我联系,...
还有就是数学不能使用计算器…….......在读初中之前原...
--Mpq
这次似乎不举行冬季长跑……看来在三鑫参加的体育项目最终是以...
--Mpq
看了你的"总结", 挺有针对性的! 相信下学期你一定会有...

RSS


首页 -> 其他题的题库->New Year congratulations
New Year congratulations

New Year congratulations

Time limit = 1 second(s)

Peter wants to congratulate his friends on the New Year day. Peter has N postcards and K envelopes, but some postcards don't fit in some envelopes (Peter knows which cards fit in which envelopes). Peter wants to congratulate as many friends as possible, but he doesn't know programming languages. Please help him: write the program that determines what envelopes and cards he should use and how.

Input: The first line of input contains three numbers N, K, C, separated by space. Then C pairs of integers follow, one pair per line. The A-th card may be put into the B-th envelope if and only if a pair (A, B) occurs in the input.

Output: The first line of ouput must contain X — the maximal number of card-envelope pairs. The next X lines must list the pairs, with pair (A, B) meaning that the A-th card must be put into the B-th envelope.

If there are many solutions, you should output one of them.

0 < N, K, C ≤ 1000 .

Input#1

2 2 3

1 1

1 2

2 1

 

Output#1

2

1 2

2 1

 

 
 
Program Mipt_010_Mpq;
Const Maxn=1000;
var
  n,c,k,answer:integer;
  sy:array[1..Maxn] of boolean;
  cx,cy:array[1..Maxn] of integer;
  g:array[1..Maxn,1..Maxn] of boolean;
procedure init;
var
  i,x,y,c:integer;
begin
  readln(n,k,c);
  for i:=1 to c do
  begin
    readln(x,y);
    g[x,y]:=true;
  end;
end;
function Find(p:integer):boolean;
var
  i:integer;
begin
  for i:=1 to k do
    if (Not sy[i]) and (g[p,i]) then
    begin
      sy[i]:=true;
      if (cy[i]=0) or (Find(cy[i])) then
      begin
        cy[i]:=p;
        cx[p]:=i;
        exit(true);
      end;
    end;
  exit(false);
end;
procedure Km;
var
  i:integer;
begin
  answer:=0;
  fillchar(cx,sizeof(cx),0);
  fillchar(cy,sizeof(cy),0);
  for i:=1 to n do
  begin
    fillchar(sy,sizeof(sy),0);
    if Find(i) then inc(answer);
  end;
  writeln(answer);
  for i:=1 to n do
    if cx[i]<>0 then
      writeln(i,' ',cx[i]);
end;
begin
  init;
  Km;
end.

网友评论

共 0 页,0 条记录  

用户名:
密码:
您的评论:
正在载入编辑器...
请输入验证码:


发 表 评 论

Mpq-中山教师家园