用户ID: 密码: 验证:

登 录

注 册 取回密码

中山教育

中山国际网

中国教育在线

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

我的资料

Mpq

博客信息

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

最新公告

欢迎光临我的博客!

最新相册

我的日历

最新评论

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

RSS


首页 -> 其他题的题库->小狗散步
小狗散步

小狗散步

Description

Grant喜欢带着他的小狗Pandog散步。Grant以一定的速度沿着固定路线走,该路线可能自交。Pandog喜欢游览沿途的景点,不过会在给定的N个点和主人相遇。小狗和主人同时从(X1Y1)点出发,并同时在(XnYn)点汇合。小狗的速度最快是Grant的两倍。当主人从一个点以直线走向另一个点时,Pandog跑向一个它感兴趣的景点。Pandog每次与主人相遇之前最多只去一个景点。

你现在的任务是:为Pandog寻找一条路线(有可能与主人的路线部分相同),使它能够游览最多的景点,并能够准时与主人在给定地点相遇或者汇合。

Input

输入文件第一行是两个整数NM( 1≤NM≤100 )
输入文件第二行的N个坐标给出了Grant的散步路线,即Pandog和主人相遇地点;
输入文件第三行的M个坐标给出了所有Pandog感兴趣的景点。
所有输入的坐标均不相同,且绝对值不超过1000

Output
第一行是经过的点数.

Sample Input

4    5
1    4    5    7    5    2    -2    4
-4    -2    3    9    1    2    -1    3    8    -3

Sample Output

6
 
 
 
Program Dog_Km_Mpq;
Const Maxn=100;
var
  v:real;
  n,m:integer;
  cx,cy:array[1..Maxn] of integer;
  sx,sy:array[1..Maxn] of boolean;
  a,b:array[1..Maxn,1..2] of integer;
  g:array[1..Maxn,1..Maxn] of boolean;
procedure init;
var
  i:integer;
begin
  readln(n,m);
  for i:=1 to n do read(a[i,1],a[i,2]);
  readln;
  for i:=1 to m do read(b[i,1],b[i,2]);
  readln;
end;

function dist(x1,x2,y1,y2:integer):real;
begin
  exit(sqrt(sqr(x1-x2)+sqr(y1-y2)));
end;
procedure Make;
var
  i,j:integer;
begin
  for i:=1 to n-1 do
    for j:=1 to m do
      if dist(a[i,1],b[j,1],a[i,2],b[j,2])+dist(a[i+1,1],b[j,1],a[i+1,2],b[j,2])<=
         2*dist(a[i,1],a[i+1,1],a[i,2],a[i+1,2])  then
           g[i,j]:=true;
end;
function Find(k:integer):boolean;
var
  i:integer;
begin
  for i:=1 to m do
    if (Not sy[i]) and (g[k,i]) then
    begin
      sy[i]:=true;
      if (cy[i]=0) or (Find(cy[i])) then
      begin
        cy[i]:=k;
        cx[k]:=i;
        exit(true);
      end;
    end;
  exit(false);
end;
procedure Km;
var
  i,tot:integer;
begin
  tot:=1;
  fillchar(cx,sizeof(cx),0);
  fillchar(cy,sizeof(cy),0);
  for i:=1 to n-1 do
  begin
    fillchar(sy,sizeof(sy),0);
    if Find(i) then inc(tot,2) else
                    inc(tot);
  end;
  writeln(tot);
end;
begin
assign(input,'dog.in'); reset(input);
assign(output,'dog.out'); rewrite(output);
  init;
  Make;
  Km;
close(input); close(output);
end.
 
Program Dog_Maxflow_Mpq;
type data=record
       limit:integer;
       flow:integer;
     end;
Const Maxn=100;
var
  n,m,s,t,Answer:integer;
  queue:array[1..Maxn*2+1] of integer;
  v:array[1..Maxn*2+1] of integer;
  a,b:array[1..Maxn,1..2] of integer;
  g:array[1..Maxn*2+1,1..Maxn*2+1] of data;
function dist(x1,x2,y1,y2:integer):real;
begin
  exit(sqrt(sqr(x1-x2)+sqr(y1-y2)));
end;
procedure init;
var
  i,j:integer;
begin
  readln(n,m);
  for i:=1 to n do read(a[i,1],a[i,2]);
  readln;
  for j:=1 to m do read(b[j,1],b[j,2]);
  readln;
  fillchar(g,sizeof(g),0);
  for i:=1 to n-1 do
    g[1,i+1].limit:=1;
  for i:=1 to n-1 do
    for j:=1 to m do
      if dist(a[i,1],b[j,1],a[i,2],b[j,2])+dist(a[i+1,1],b[j,1],a[i+1,2],b[j,2])<=
         2*dist(a[i,1],a[i+1,1],a[i,2],a[i+1,2])  then
           g[i+1,j+n].limit:=1;
  for i:=1 to m do
    g[i+n,n+m+1].limit:=1;
end;
function Mins(a,b:integer):integer;
begin
  if a>b then exit(b) else exit(a);
end;
procedure MaxFlow;
var
  i,j,Min,head,last:integer;
begin
  Answer:=n;
  s:=1; t:=n+m+1;
  while true do
  begin
    fillchar(v,sizeof(v),0);
    head:=1; last:=1;
    v[1]:=s;
    queue[1]:=1;
    repeat
      if head<=last then i:=queue[head] else break;
      for j:=1 to t do
        if v[j]=0 then
          if g[i,j].flow<g[i,j].limit then
          begin
            inc(last);
            queue[last]:=j;
            v[j]:=i;
          end else
          if g[j,i].flow>0 then
          begin
            inc(last);
            queue[last]:=j;
            v[j]:=-i;
          end;
      inc(head);
    until v[t]<>0;
    if v[t]=0 then break;
    Min:=Maxint;
    i:=t;
    while i<>s do
    begin
      if v[i]>0 then Min:=Mins(g[v[i],i].limit-g[v[i],i].flow,Min) else
                     Min:=Mins(g[i,abs(v[i])].flow,Min);
      i:=abs(v[i]);
    end;
    i:=t;
    inc(Answer,Min);
    while i<>s do
    begin
      if v[i]>0 then inc(g[v[i],i].flow,Min) else
                     dec(g[i,abs(v[i])].flow,Min);
      i:=abs(v[i]);
    end;
  end;
  writeln(Answer);
end;
begin
assign(input,'dog.in'); reset(input);
assign(output,'dog.out'); rewrite(output);
  init;
  Maxflow;
close(input); close(output);
end.

 

 

网友评论

共 0 页,0 条记录  

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


发 表 评 论

Mpq-中山教师家园