2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)V - Gears

Problem V | limit 4 seconds
Gears
A set of gears is installed on the plane. You are given the center coordinate and radius of each
gear. For a given input and output gear, indicate what happens to the output gear if you attempt
to rotate the input gear.
Input
The rst line of input contains a single positive integer n (2 n 1;000), the total number of
gears. Following this will be n lines, one per gear, containing three space-separated integers xi,
yi, and ri (?104 xi; yi 104, 1 ri 104), indicating the center coordinate and the radius of
the ith gear. Assume the tooth count for each gear is suciently high that the gears always mesh
correctly. It is guaranteed that the gears do not overlap with each other. The input gear is the
rst gear in the list, and the output gear is the last gear in the list.
Output
If the input gear cannot move, print, on a single line, \The input gear cannot move." (without
the quotation marks).
If the input gear can move but is not connected to the output gear, print, on a single line,
\The input gear is not connected to the output gear." (without the quotation marks).
Otherwise, print, on a single line, the ratio the output gear rotates with respect to the input
gear in the form of \##:##" (without the quotation marks), in reduced form. If the output gear
rotates in the opposite direction as the input gear, write the ratio as a negative ratio. For example,
if the output gear rotates clockwise three times as the input gear rotates counterclockwise twice,
the output should be -3:2.

input

2
0 0 100
200 0 100

output

-1:1

please do not look the solution

无向图染色..

原文地址http://www.cnblogs.com/pk28/p/5774373.html

/* ***********************************************
Author        :guanjun
Created Time  :2016/8/15 19:33:39
File Name     :v0k.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
    int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
    }
};

bool cmp(int a,int b){
    return a>b;
}
int x[1100],y[1100],r[1100];
vector<int>edge[1100];
bool judge(int a,int b,int c,int d,int e){
    if((a-c)*(a-c)+(b-d)*(b-d)==e*e)return true;
    return false;
}
int vis[1100];
int flag;
bool dfs(int u){
    for(int i=0;i<edge[u].size();i++){
        int v=edge[u][i];
        if(vis[u]==vis[v])return false;
        if(!vis[v]){
            vis[v]=3-vis[u];
            if(!dfs(v))return false;
        }
    }
    return true;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>x[i]>>y[i]>>r[i];
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(judge(x[i],y[i],x[j],y[j],r[i]+r[j])){
                edge[i].push_back(j);
                edge[j].push_back(i);
            }
        }
    }
    cle(vis);
    vis[1]=1;
    if(!dfs(1)){
        puts("The input gear cannot move.");
    }
    else{
        if(vis[n]==0){
            puts("The input gear is not connected to the output gear.");
        }
        else{
            if(vis[n]==2)cout<<"-";
            int k=__gcd(r[1],r[n]);
            printf("%d:%d\n",r[1]/k,r[n]/k);
        }
    }
    return 0;
}

 

一些套路,比如二分图染色可以这么写

int col[maxn];
bool dfs(int u, int c) {
    if (col[u]) {
        if (col[u] == c) return true;
        else return false;
    }
    col[u] = c;
    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i];
        if (!dfs(v, 3 - c)) return false;
    }
    return true;
}
View Code

 

转载于:https://www.cnblogs.com/pk28/p/5774373.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值