栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2039 The Dog Task

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2039 The Dog Task

#include<iostream>#include<set>#include<string.h>#include<stdlib.h>#include<algorithm>#include<stdio.h>#include<cmath>using namespace std;enum {    SIZ = 104,};struct Point {    int x, y;    void readIn(){        scanf("%d%d", &x,&y);    }    double dist(const Point&o)const{        double r = (x-o.x)*(x-o.x);        r += (y-o.y)*(y-o.y);        r = sqrt(r);        return r;    }};const double eps = 1e-7;Point bob[SIZ];Point dog[SIZ];bool tab[SIZ][SIZ];bool vis[SIZ];int mat[SIZ];int RN, DM;int dfs(int p){  int i,t;  for(i=0;i<RN;i++)    if(tab[i][p] && !vis[i]){      vis[i]=1;      t=mat[i];      mat[i]=p;      if(t==-1 || dfs(t))          return 1;      mat[i]=t;    }  return 0;}int get_match(){  int i,res=0;  memset(mat,-1,sizeof(mat));  for(i=0;i<DM;i++){      memset(vis,0,sizeof(vis));      if(dfs(i))         res++;  }  return res;}void fun(){    int s = get_match() + RN + 1;    printf("%dn", s);    printf("%d %d", bob[0].x, bob[0].y);    for (int i=1; i<=RN; ++i){        if (mat[i-1] != -1) { printf(" %d %d", dog[mat[i-1]].x, dog[mat[i-1]].y);        }        printf(" %d %d", bob[i].x, bob[i].y);    }    printf("n");}void readIn(){    scanf("%d%d",&RN,&DM);    int i;    for (i=0; i<RN; ++i){        bob[i].readIn();    }    for (i=0; i<DM; ++i){        dog[i].readIn();    }    memset(tab, 0, sizeof(tab));    double s, a, b;    --RN;    for (i=0; i<RN; ++i){        s = bob[i].dist(bob[i+1]);        for (int j=0; j<DM; ++j){ a = bob[i].dist(dog[j]); b = bob[i+1].dist(dog[j]); if (s*2 + eps >= a + b){     tab[i][j] = true; }        }    }}int main(){    int tst;    scanf("%d",&tst);    while(tst-- > 0){        readIn();        fun();        if (tst) printf("n");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375821.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号