zoukankan      html  css  js  c++  java
  • ZJNU 2133

    将辈分差距转为数字

    例如 A 是 B son

    A=B-1

    A 是 B grandfather

    A=B+2
    然后编号1数字设置为0,建图bfs

    最后搜索编号2到100是否存在>0的数即可

    #include<bits/stdc++.h>
    using namespace std;
    typedef pair<int,int> P;
    vector<P> v[105];
    queue<int> q;
    int dis[105];
    bool vis[105];
    int main(){
        memset(dis,0x3f,sizeof dis);
        int N,i,now,cnt,a,b;
        char s[15];
        scanf("%d",&N);
        while(N--){
            scanf("%d is %d's %s",&a,&b,s);
            if(strcmp(s,"father.")==0){
                v[a].push_back(P(b,-1));
                v[b].push_back(P(a,1));
            }
            else if(strcmp(s,"son.")==0){
                v[a].push_back(P(b,1));
                v[b].push_back(P(a,-1));
            }
            else if(strcmp(s,"brother.")==0){
                v[a].push_back(P(b,0));
                v[b].push_back(P(a,0));
            }
            else if(strcmp(s,"grandson.")==0){
                v[a].push_back(P(b,2));
                v[b].push_back(P(a,-2));
            }
            else if(strcmp(s,"grandfather.")==0){
                v[a].push_back(P(b,-2));
                v[b].push_back(P(a,2));
            }
        }
        vis[1]=true;
        dis[1]=0;
        q.push(1);
        while(!q.empty()){
            now=q.front();
            q.pop();
            cnt=v[now].size();
            for(i=0;i<cnt;i++)
                if(!vis[v[now][i].first]){
                    vis[v[now][i].first]=true;
                    dis[v[now][i].first]=dis[now]+v[now][i].second;
                    q.push(v[now][i].first);
                }
        }
        bool flag=true;
        for(i=2;i<=100;i++)
            if(dis[i]!=0x3f3f3f3f&&dis[i]>0){
                flag=false;
                break;
            }
        puts(flag?"2333333...":"ku jiu ru hou xin zuo tong.");
        
        return 0;
    }
  • 相关阅读:
    phpstorm操作集锦
    图片、音频获取二进制流或url的blob值
    sublime text 3 快捷键
    dd与sql 打印工具
    php生成二维码(可带logo)
    jQuery append加入的元素 绑定事件无效
    Linux运维架构师学习之路
    硬盘安装win7
    Composer安装与使用
    Js循环做法
  • 原文地址:https://www.cnblogs.com/stelayuri/p/12236294.html
Copyright © 2011-2022 走看看