HDU 4948
题目大义:
给一张图,任意两点间有单向边,找出一种方案,使得每个新入队的点与队中的点距离<=2。
题解:
贪心,从最后入队点开始反向插入,每次找出最大入度的点入队。
只需证明最大入度点A与所有未入队的点距离<=2
每次加入最大入度点A,设未入队的B集与A距离为1,假设若有未入队的点C与A距离>2,则必有A->C,B->C,则有C入度>A,矛盾!
故恒有解
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x)) using namespace std; struct City
{
int out,res;
}city[]; int n;
char p; bool cmp(City x, City y)
{
return x.out<y.out;
} int main()
{
while(scanf("%d",&n)!=EOF && n)
{
for(int i=; i<n; i++)
{
city[i].res=i;
city[i].out=;
}
for(int i=; i<n; i++)
{
getchar();
for(int j=; j<n; j++)
{
scanf("%c",&p);
if(p=='') city[i].out++;
}
}
sort(city,city+n,cmp);
for(int i=n-; i>; i--)
printf("%d ",city[i].res+);
printf("%d\n",city[].res+);
}
return ;
}
HDU 4948的更多相关文章
- hdu 4948 Kingdom(推论)
hdu 4948 Kingdom(推论) 传送门 题意: 题目问从一个城市u到一个新的城市v的必要条件是存在 以下两种路径之一 u --> v u --> w -->v 询问任意一种 ...
- 拓扑排序 --- hdu 4948 : Kingdom
Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 4948 (傻比图论)
Kingdom Problem Description Teacher Mai has a kingdom consisting of n cities. He has planned the tra ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- CentOS 6.5系统上安装MySQL数据库
1.查看系统是否安装了MySQL 使用命令: #rpm -qa | grep mysql 2.卸载已安装的MySQL 卸载mysql命令如下: #rpm ...
- ffmpeg mp3转ogg的命令
ffmpeg.exe -y -i bb.mp3 -acodec libvorbis -ab 128k bb.ogg
- c++ freelockquque
http://www.boost.org/doc/libs/1_56_0/doc/html/boost/lockfree/queue.html Class template queue boost:: ...
- EXT--当defaultType与items的子组件默认xtype冲突时items的子组件的xtype为panel
示例图 直接看下面示例代码: /** * 获取导入表单 * @returns {Ext.FormPanel} */ function getImportForm() { return new Ext. ...
- Unix无缓冲文件操作函数、文件信息查询
问题描述: Unix无缓冲文件操作函数.文件信息查询 问题解决: struct stat 结构体信息: 具体代码: 具体源文件:
- CSS滤镜详解
语法:STYLE="filter:filtername(fparameter1, fparameter2...)" (Filtername为滤镜的名称,fparameter1.fp ...
- 基于AgileEAS.NET企业应用开发平台的分布式解决方案
开篇 分布式应用 AgileEAS.NET基于Microsoft .Net构件技术而构建,Microsoft .Net最吸引人的莫过于分布式应用技术,基已经提供了XML WebService. .Ne ...
- script是什么
script是什么 scirpt就是一个命令,可以制作一份记录输出到终端的记录.对于那些想要真实记录终端会话的人来说,这很有用.该记录可以保存并在以后再打印出来. 怎么用 默认情况下,我们可以通过在终 ...
- selenium实战脚本集——新浪微博发送QQ每日焦点(火狐)
selenium实战脚本集(1)——新浪微博发送QQ每日焦点,乙醇用谷歌实现的,下边是用火狐实现的. 代码如下: # coding = utf-8 from selenium import webdr ...
- Mac 如果一定要写个锁屏程序的话就这样
package test; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import ...