样例错误,测试AC?
查看原帖
样例错误,测试AC?
1254085
ZJ_lzz楼主2025/1/5 14:25

输入输出样例

输入

44 55

11 44 55 77 55 22 2-2 44

4-4 2-2 33 99 11 22 1-1 33 88 3-3

预期输出

66

11 44 33 99 55 77 55 22 11 22 2-2 44

实际输出

66

11 44 11 22 55 77 55 22 33 99 2-2 44

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int m,ans[110],match[110];
bool vis[110],e[110][110];
struct node 
{
	double x,y;
}grant[110],doge[110];
bool dfs(int u)
{
    for(int i=1;i<=m;i++)
    {
    	if(e[u][i]&&!vis[i])
        {
            vis[i]=true;
            if(!match[i]||dfs(match[i])) 
			{
			    match[i]=u; 
				ans[u]=i; 
				return true;
			}
        }
	}
    return false;
}
inline double get_dist(const node &a,const node &b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
    int n,cnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) 
	{
		scanf("%lf%lf",&grant[i].x,&grant[i].y);
	}
    for(int i=1;i<=m;i++)
    {
        scanf("%lf%lf",&doge[i].x,&doge[i].y);
        for(int j=1;j<n;j++)
        {
        	if(2.0*get_dist(grant[j],grant[j+1])>=get_dist(grant[j],doge[i])+get_dist(doge[i],grant[j+1]))
            {
            	e[j][i]=true;
			}
		}      
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=m;j++) 
		{
			vis[j]=false;
		}
        if(dfs(i)&&++cnt==m) 
		{
			break ;
		}
    }

    printf("%d\n",n+cnt);
    for(int i=1;i<=n;i++)
    {
        printf("%.0lf %.0lf ",grant[i].x,grant[i].y);
        if(ans[i]) 
		{
			printf("%.0lf %.0lf ",doge[ans[i]].x,doge[ans[i]].y);
		}
    }
    return 0;
}
2025/1/5 14:25
加载中...