• 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
    ",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;
    }
  • 相关阅读:
    H5上传图片
    关于mysql本地无法连接问题
    node.js、git、bootstrap等安装配置
    angularJS2-日志
    day21-python操作mysql1
    day20-正则表达式练习
    day19-python的正则表达式2
    day18-python的正则表达式
    day17-json格式转换
    day16-python常用的内置模块2
  • 原文地址:https://www.cnblogs.com/ecustlegendn324/p/13498704.html
Copyright © 2020-2023  润新知