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 ...
随机推荐
- Android偏好设置(3)启动偏好设置后显示的界面PreferenceActivity和PreferenceFragment
Creating a Preference Activity To display your settings in an activity, extend the PreferenceActivit ...
- .net 发送邮件验证码
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Ma ...
- Android学习备忘笺01Activity
01.设置视图 在Android Studio新建的项目中,通过 setContentView(R.layout.activity_main);方法将res/layout/activity_main. ...
- Android开发中查看未root真机的app数据库
在Android开发中,如果用到数据库来储存数据,那么难免就要查看数据库中的内容,可是对于未root的真机来说,查看数据库就不是那么容易了,如果仅仅为了查看数据库再把手机root了,有点得不偿失,所以 ...
- 重构30-Return ASAP(尽快返回)
该话题实际上是诞生于移除箭头反模式重构之中.在移除箭头时,它被认为是重构产生的副作用.为了消除箭头,你需要尽快地return. ) { orderTotal = sum(products)) { or ...
- 有意思的String字符工具类
对String的操作是Java攻城师必备的,一个优秀的攻城师是懒惰,他会把自己的一些常见的代码写成可提供拓展和复用的工具类或者工具库,这些是这些优秀工程师的法宝. 我就先从String这个基本操作开始 ...
- JS获取服务器端控件ID
很多时候我们需要在JS中对服务器端控件进行一些简单处理,但是这个时候没有必要回发到服务器,让服务器去处理,这个时候就又要用到JS了 那么怎么去获取这个服务器端控件呢?我们知道服务器最终返回到用户界面的 ...
- jQuery 的DOM操作
DOM创建节点及节点属性 创建元素:document.createElement设置属性:setAttribute添加文本:innerHTML加入文档:appendChild append()前面是被 ...
- Code::Blocks使用与调试一条龙
CodeBlocks创建C语言工程版本13.12 选择"create a new project" 选择第四个,点击"go" 4 选择"C&quo ...
- Java并发——volatile关键字的使用
volatile关键字的使用volatile关键字原理适合使用volatile关键字的情况当且仅当满足以下所有条件时,才==应该==使用volatile关键字:volatile关键字的作用volati ...