I. Disks

纯粹的發表於2024-06-17

原題連結

題解

對於一組相切的圓來說,其中一個圓變大,其相鄰的圓變小,然後相鄰的相鄰的圓變大...而要讓總半徑和變小,一定得是總的變小的圓更多

實施

先判斷一組圓能不能發生變化,然後再累積變大和變小的圓個數

code

#include<bits/stdc++.h>
using namespace std;

#define ll long long
const ll inf=2e14;

struct node
{
    ll x,y,r;
}c[1005];

vector<ll> G[1005];

ll vis[1005]={0};

inline void read(ll &x) {
	x = 0;
	ll flag = 1;
	char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')flag = -1;
        c = getchar();
    }
	while(c >= '0' && c <= '9') {
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = getchar();
	}
	x *= flag;
}

inline void write(ll x)
{
    if(x < 0){
    	putchar('-');
		x = -x;
	}
    if(x > 9)
		write(x / 10);
    putchar(x % 10 + '0');
}

ll res=0;
void dfs(ll now, ll fa, ll op)
{
    res+=op;
    vis[now]=op;
    for(auto next:G[now])
    {
        if(next==fa) continue;
        if(!vis[next])
        {
            dfs(next,now,-op);
        }
        else if(vis[next]==vis[now]) res+=inf;
    }

}

int main()
{
    ll n;
    read(n);
    for(ll i=1; i<=n; i++)
    {
        read(c[i].x);
        read(c[i].y);
        read(c[i].r);
    }

    for(ll i=1; i<=n; i++)
    {
        for(ll j=1; j<i; j++)
        {
            ll x1=c[i].x, x2=c[j].x, y1=c[i].y, y2=c[j].y, r1=c[i].r, r2=c[j].r;
            if((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)==(r1+r2)*(r1+r2))
            {
                G[i].push_back(j);
                G[j].push_back(i);
            }
        }
    }

    for(ll i=1; i<=n; i++)
    {
        if(!vis[i])
        {
            res=0;
            dfs(i,i,1);
            if(res&&res<=n)
            {
                puts("YES");
                return 0;
            }
        }
    }

    puts("NO");
    return 0;
}


相關文章