zoukankan      html  css  js  c++  java
  • codeforces

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 #define rep(i,a,b) for(int i = a;i <= b;++ i)
     4 #define per(i,a,b) for(int i = a;i >= b;-- i)
     5 #define mem(a,b) memset((a),(b),sizeof((a)))
     6 #define FIN freopen("in.txt","r",stdin)
     7 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
     8 #define pb push_back
     9 typedef long long LL;
    10 typedef pair<int, int> PIR;
    11 const int N = 1e+5;
    12 
    13 int n, use, stu[N];
    14 bool vis[N];
    15 vector <int> G[N];
    16 struct Node{
    17     LL x, y;
    18     LL r;
    19 }node[N];
    20 
    21 bool judge(int i, int j){
    22     LL xi = node[i].x-node[j].x, yi = node[i].y-node[j].y;
    23     LL ri = node[i].r+node[j].r;
    24     return (xi*xi+yi*yi) == ri*ri;
    25 }
    26 void Test(){
    27     cout << "-----------TEST----------" << endl;
    28     rep(i, 1, n){
    29         cout << i << ": ";
    30         rep(j, 0, (int)G[i].size()-1)   cout << G[i][j] << " ";
    31         cout << endl;
    32     }
    33     cout << endl;
    34 }
    35 
    36 void bfs(){
    37     queue <PIR> Q;
    38     mem(stu, -1);
    39     mem(vis, false);
    40     use = 1;
    41     Q.push(PIR(1, 0));
    42     stu[1] = 0;
    43     vis[1] = true;
    44     while(!Q.empty()){
    45         PIR pir = Q.front(); Q.pop();
    46         int u = pir.first, st = pir.second;
    47         if(u == n){
    48             if(st^0 == 1)   cout << "-";
    49             LL gcd = __gcd(node[n].r, node[1].r);
    50             cout << node[1].r/gcd << ":" << node[n].r/gcd << endl;
    51             return ;
    52         }
    53         rep(i, 0, (int)G[u].size()-1){
    54             int v = G[u][i];
    55             if(stu[v] != -1 && stu[v]^st == 0){
    56                 cout << "The input gear cannot move." << endl;
    57                 return ;
    58             }
    59 
    60             if(vis[v])  continue;
    61             if(stu[v] == -1 || (stu[v] != -1 && stu[v]^st == 1)){
    62                 stu[v] = st^1;
    63                 vis[v] = true;
    64                 Q.push(PIR(v, st^1));
    65             }
    66         }
    67     }
    68     cout << "The input gear is not connected to the output gear." << endl;
    69     return ;
    70 }
    71 int main()
    72 {IO;
    73     //FIN;
    74     cin >> n;
    75     rep(i, 1, n)    cin >> node[i].x >> node[i].y >> node[i].r;
    76     rep(i, 1, n)    rep(j, i+1, n)  if(judge(i, j)) { G[i].pb(j); G[j].pb(i); }
    77     //Test();
    78     bfs();
    79     return 0;
    80 }
    View Code
  • 相关阅读:
    [luoguP2342] 叠积木(并查集)
    [luoguP2147] [SDOI2008]Cave 洞穴勘测(并查集 || lct)
    [POJ1611]The Suspects(并查集)
    [POJ2912]Rochambeau(并查集)
    网站图片增强JS插件2.0(兼容IE&FF)
    jQuery简单纯文字提示条
    复选框--全选/全不选/反选。简易版
    Magic Grid ComboBox JQuery 版
    SWFObject 的基本使用方法
    全局Timestamp管理器 检测js执行时间
  • 原文地址:https://www.cnblogs.com/NWUACM/p/6724744.html
Copyright © 2011-2022 走看看