hdu6853 Jogging
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6853
提示:头文件一定要多...不然编译不过doge
#include<iostream>
#include<fstream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
#include<cstdio>
#include<sstream>
#include<cassert>
#include<bitset>
#include<unordered_map>
#include<climits>
#define ll long long
using namespace std;
int X[] = {0, -1, -1, 0, 1, 1, 1, 0, -1};
int Y[] = {0, 0, 1, 1, 1, 0, -1, -1, -1};
ll res1, res2;
void BFS(ll x0, ll y0)
{
res1 = res2 = 0;
set<pair<ll, ll> > vis;
queue<pair<ll, ll> > q;
q.emplace(x0, y0);
vis.emplace(x0, y0);
while(!q.empty()){
ll nowx, nowy;
tie(nowx, nowy) = q.front();//系起队首の元素
res2++;//初始点已在其中,因而最后不必再加一
q.pop();
if(nowx == nowy){
res1 = 0;
res2 = 1;
break;
}
for(int i = 1 ; i <= 8 ; i++){
ll xi = nowx + X[i], yi = nowy + Y[i];
if(__gcd(xi, yi) > 1){
res2++;//总
if(vis.count(make_pair(xi, yi))) continue;
vis.emplace(xi, yi);
q.emplace(xi, yi);
}
}
if(res1 == 0) res1 = res2;//
}
ll gcd = __gcd(res1, res2);
res1 /= gcd;
res2 /= gcd;
here:
printf("%lld/%lld\n",res1,res2);
//起点の度数+1 / 总の度数+k //k表示连通块的个数(本题就一个连通块叭)
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ll a, b;
scanf("%lld %lld",&a,&b);
BFS(a, b);
}
return 0;
}