BZOJ4050 [Cerc2014] Wheels

模拟即可

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define MAXN 1010
#define MAXM 1010
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define eps 1e-8
struct cir{
    int x;
    int y;
    int r;
};
cir c[MAXN];
int n;
ll fz[MAXN],fm[MAXN];
int q[MAXN],hd,tl;
bool fwd[MAXN];
ll gcd(ll x,ll y){
    return (!y)?x:gcd(y,x%y);
}
int main(){
    int i,x,y;
    int tmp;
    scanf("%d",&tmp);
    while(tmp--){
        scanf("%d",&n);
        for(i=1;i<=n;i++){
            scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].r);
        }
        memset(fz,0,sizeof(fz));
        fz[1]=1;
        fm[1]=1;
        fwd[1]=1;
        hd=tl=0;
        q[tl++]=1;
        while(hd!=tl){
            x=q[hd++];
            for(i=1;i<=n;i++){
                if(x!=i&&!fz[i]&&(ll)(c[i].x-c[x].x)*(c[i].x-c[x].x)+(c[i].y-c[x].y)*(c[i].y-c[x].y)==(ll)(c[i].r+c[x].r)*(c[i].r+c[x].r)){
                    fz[i]=fz[x]*c[x].r;
                    fm[i]=fm[x]*c[i].r;
                    fwd[i]=fwd[x]^1;
                    ll g=gcd(fz[i],fm[i]);
                    fz[i]/=g;
                    fm[i]/=g;
                    q[tl++]=i;
                }
            }
        }
        for(i=1;i<=n;i++){
            if(!fz[i]){
                printf("not moving\n");
            }else{
                  
                if(fm[i]==1){
                    printf("%d ",fz[i]);
                }else{
                    printf("%d/",fz[i]);
                    printf("%d ",fm[i]);
                }
                printf(fwd[i]?"clockwise\n":"counterclockwise\n");
            }
        }
    }
    return 0;
}
  
/*
  
*/


你可能感兴趣的:(BZOJ,BFS)