Kingdom

Problem Description
Teacher Mai has a kingdom consisting of n cities. He has planned the transportation of the kingdom. Every pair of cities has exactly a one-way road.

He wants develop this kingdom from one city to one city.

Teacher Mai now is considering developing the city w. And he hopes that for every city u he has developed, there is a one-way road from u to w, or there are two one-way roads from u to v, and from v to w, where city v has been developed before.

He gives you the map of the kingdom. Hope you can give a proper order to develop this kingdom.

 

Input
There are multiple test cases, terminated by a line "0".

For each test case, the first line contains an integer n (1<=n<=500).

The following are n lines, the i-th line contains a string consisting of n characters. If the j-th characters is 1, there is a one-way road from city i to city j.

Cities are labelled from 1.

 

Output
If there is no solution just output "-1". Otherwise output n integers representing the order to develop this kingdom.
 

Sample Input
3 011 001 000 0
 

Sample Output
1 2 3

题意 :给出一个图满足两两之间都有一条边,然后选择建设的城市,满足当前选的城市和之前选的城市之间最多距离为2.  求建设城市的顺序。

sl :刚开始傻逼了没看到红色的话,比赛的时候更傻逼,提都理解错了。妈蛋白敲了100+代码。 其实选下最大度数的节点就好了,证明就是题解

的那个证明,反证。因为确保都有一条边所以题解是对的,我说开始为什么看着不对呢

#include <cstdio>

#include <cstring>
#include <algorithm>
#include <vector>
#include <vector>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MAX = +;
char str[MAX][MAX];
int in[MAX],vis[MAX],G[MAX][MAX];
vector<int> res;
int main() {
    int n;
    while(scanf("%d",&n)==&&n) {
        memset(G,,sizeof(G));
        memset(vis,,sizeof(vis));
        memset(in,,sizeof(in));
        res.clear();
        for(int i=;i<=n;i++) {
            scanf("%s",str[i]+);
        }
        for(int i=;i<=n;i++) {
            for(int j=;j<=n;j++) {
                if(str[i][j]=='') {
                     G[i][j]=; in[j]++;
                }
            }
        }
        for(int i=;i<=n;i++) {
            int node,Max=;
            for(int j=;j<=n;j++) {
                if(!vis[j]) {
                    if(Max<=in[j]) {
                        node=j; Max=in[j];
                    }
                }
            }
            for(int j=;j<=n;j++) if(G[node][j]) in[j]--;
            vis[node]=;
            res.push_back(node);
        }
       // printf("s");
        for(int i=res.size()-;i>=;i--) {
            if(!i) printf("%d\n",res[i]);
            else printf("%d ",res[i]);
        }
    }
    return ;
}

HDU 4948 (傻比图论)的更多相关文章

  1. hdu 4948 Kingdom(推论)

    hdu 4948 Kingdom(推论) 传送门 题意: 题目问从一个城市u到一个新的城市v的必要条件是存在 以下两种路径之一 u --> v u --> w -->v 询问任意一种 ...

  2. HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. HDU 4435 charge-station bfs图论问题

    E - charge-station Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  4. HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)     Problem ...

  5. 拓扑排序 --- hdu 4948 : Kingdom

    Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. HDU 4948

    题目大义: 给一张图,任意两点间有单向边,找出一种方案,使得每个新入队的点与队中的点距离<=2. 题解: 贪心,从最后入队点开始反向插入,每次找出最大入度的点入队. 只需证明最大入度点A与所有未 ...

  7. HDU 2647 Reward(图论-拓扑排序)

    Reward Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is comin ...

  8. HDU 4467 Graph(图论+暴力)(2012 Asia Chengdu Regional Contest)

    Description P. T. Tigris is a student currently studying graph theory. One day, when he was studying ...

  9. hdu 3357 Stock Chase (图论froyd变形)

    Stock Chase Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. .net 环境下c# 通信

    .net环境下通信主要掌握 通信协议(UDP&TCP). 网络抓包工具().:使用方法 点对点通信,IP组播,广播通信 c#中结构体转为字节流方式 c#结构体与c++结构体转换对应关系 开源的 ...

  2. AJPFX关于构造器的总结

    构造器        构造器定义        构造器作用        构造器特点        构造器修饰符        默认构造器        构造器重载        构造器和一般函数的区 ...

  3. Spark学习之Spark Streaming(9)

    Spark学习之Spark Streaming(9) 1. Spark Streaming允许用户使用一套和批处理非常接近的API来编写流式计算应用,这就可以大量重用批处理应用的技术甚至代码. 2. ...

  4. ORM-PetaPoco

    PetaPoco有以下特色:--------------------------20170715姜彦 微小,没有依赖项……单个的C#文件可以方便的添加到任何项目中. 工作于严格的没有装饰的Poco类, ...

  5. vscode前端开发软件配搭好用的插件

    使用方法,可以在官网中搜索需要的插件或者在VsCode的“”扩展“”中搜索需要的插件添加方法使用Ctrl+P, 输入 ext install xxxx ,搜索要安装的插件,点击安装按钮即可(各取所需插 ...

  6. restful api的简单理解

    百度百科的描述:一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制. RES ...

  7. CentOS 6.4 linux下编译安装 LNMP环境

    1.nginx编译安装 2.PHP编译安装 3.mysql编译安装 4.NGINX配置模板 5.CentOS 6.4 php-fpm 添加service 添加平滑启动/重启

  8. 洛谷 P1886 滑动窗口 (数据与其他网站不同。。)

    题目描述 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值. 例如: The array i ...

  9. HDU_1856_带权并查集

    有10000000个同学,他们之间可能是直接朋友或者间接朋友,问最大的朋友圈有多少人. 一直觉得10000000的数组开不了,用map优化了一下,结果能开,且10000000也不会超时... #inc ...

  10. 安卓 Android 简单数据库(增删改查)

    <Button android:id="@+id/delete_btn" android:layout_width="wrap_content" andr ...