HDU 4948 (傻比图论)
Kingdom
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.
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.
3 011 001 000 0
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 (傻比图论)的更多相关文章
- hdu 4948 Kingdom(推论)
hdu 4948 Kingdom(推论) 传送门 题意: 题目问从一个城市u到一个新的城市v的必要条件是存在 以下两种路径之一 u --> v u --> w -->v 询问任意一种 ...
- HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 4435 charge-station bfs图论问题
E - charge-station Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))
传递 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- 拓扑排序 --- hdu 4948 : Kingdom
Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 4948
题目大义: 给一张图,任意两点间有单向边,找出一种方案,使得每个新入队的点与队中的点距离<=2. 题解: 贪心,从最后入队点开始反向插入,每次找出最大入度的点入队. 只需证明最大入度点A与所有未 ...
- HDU 2647 Reward(图论-拓扑排序)
Reward Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is comin ...
- 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 ...
- hdu 3357 Stock Chase (图论froyd变形)
Stock Chase Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- Matlab实现Butterworth滤波器 分类: 图像处理 2014-06-02 00:05 527人阅读 评论(0) 收藏
下面是用Matlab实现的Butterworth高通.低通滤波器. clc;clear all;close all; I=imread('cameraman.tif'); subplot(3,2,1) ...
- windows deintall 12c client
1.unintall: close all oracle app C:\app\client\CICadmin\product\12.1.0\client_1\deinstall deinstall ...
- C#特性的介绍及应用场景
1.特性的任务:特性就是为了支持对象添加一些自我描述的信息,不影响类封装的前提添加额外信息.如果你用这个信息,那特性就有用:如果你不需要这个信息,那么这个特性就没用. 2.特性的基类:Attribut ...
- bootstrap框架栅格系统使用
使用的前端框架 bootstrap框架 Bootstrap是一个响应式的框架 我们在使用的时候主要使用的是它的网格系统, 1.bootstrap布局 布局容器:.container(用于固定宽度并支 ...
- hihocoder 分隔相同字符
思路: 枚举,贪心. 在“合法”的前提下放置越排在前边的字母越好. “合法”:'a' - 'z'中没有一个字母的个数超过当前串剩余长度的一半(偶数情况下)或长度的一半加1(奇数情况下). 实现: #i ...
- windows server 2008 r2 IIS7下网站配置 只允许指定的IP地址访问
步骤一.找到ip地址和域限制 步骤二.添加全部拒绝 步骤三.添加允许访问的ip地址(局域网填写局域网ip,公网填写公网ip) 步骤四:如果想要拒绝某些ip访问,直接在规则中添加拒绝条目就可以
- 【数据分析 R语言实战】学习笔记 第四章 数据的图形描述
4.1 R绘图概述 以下两个函数,可以分别展示二维,三维图形的示例: >demo(graphics) >demo(persp) R提供了多种绘图相关的命令,可分成三类: 高级绘图命令:在图 ...
- Windows下使用JMeter
简介 Apache JMeter是100%纯java桌面应用程序,被设计用来测试C/S结构的软件(例如web应用程序).它可以被用来测试包括基于静态和动态资源程序的性能,例如静态文件,Java Ser ...
- MVC 附件在线预览
原因:应客户需求,在系统中浏览附件内容,需要先下载到本地然后打开,对使用造成了不便,要求可以不需下载直接在浏览器中打开减少操作步骤. 领导给了3天时间,最后查找方法,写测试项目,往正式项目添加,测试, ...
- Shiro的subject实质上是当前执行用户的特定视图。
Shiro的subject实质上是当前执行用户的特定视图. 通过org.apache.shiro.SecurityUtils可以查询当前执行用户: Subject currentUser = Secu ...