CodeForces - 28A Bender Problem【水题】

题目链接:https://codeforces.com/contest/28/problem/A

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
typedef double db;
static const int MAXN=500+10;
static const db EPS=1e-10;
struct Point{
    int x,y;
    void input() { scanf("%d%d",&x,&y); }
}point[MAXN];
int seg[MAXN];
bool vis[MAXN];
int ans[MAXN];
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) point[i].input();
    point[0].x=point[n].x; point[0].y=point[n].y;
    point[n+1].x=point[1].x; point[n+1].y=point[1].y;
    for(int i=1;i<=m;i++) scanf("%d",&seg[i]);
    bool flag=true;
    for(int i=1;i<=n;i+=2)
    {
        double dis=sqrt((point[i].x-point[i-1].x)*(point[i].x-point[i-1].x)+(point[i].y-point[i-1].y)*(point[i].y-point[i-1].y))
          +sqrt((point[i].x-point[i+1].x)*(point[i].x-point[i+1].x)+(point[i].y-point[i+1].y)*(point[i].y-point[i+1].y));
        for(int j=1;j<=m;j++)
        {
            if(!vis[j] && fabs(dis-seg[j])<EPS)
            {
                vis[j]=true;
                ans[i]=j;
                break;
            }
            if(j==m) flag=false;
        }
    }       
    if(!flag)
    {
        flag=true;
        memset(vis,0,sizeof(vis));
        memset(ans,0,sizeof(ans));
        for(int i=2;i<=n;i+=2)
        {
            double dis=sqrt((point[i].x-point[i-1].x)*(point[i].x-point[i-1].x)+(point[i].y-point[i-1].y)*(point[i].y-point[i-1].y))
            +sqrt((point[i].x-point[i+1].x)*(point[i].x-point[i+1].x)+(point[i].y-point[i+1].y)*(point[i].y-point[i+1].y));
            for(int j=1;j<=m;j++)
            {
                if(!vis[j] && fabs(dis-seg[j])<EPS)
                {
                    vis[j]=true;
                    ans[i]=j;
                    break;
                }
                if(j==m) flag=false;
            }
        }      
    }
    if(flag)
    {
        puts("YES");
        for(int i=1;i<=n;i++)
            printf("%d ",ans[i]?ans[i]:-1);
    }
    else puts("NO");
    return 0;
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页