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 ...
随机推荐
- eclipse下如何关联android-support-v4.jar源码
一.首先导入jar包 如果android-support-v4.jar包在libs目录下,先将它移除.然后点选中项目右键 --->properties-->javabuildpath--& ...
- Daily Scrum 11.8
摘要:本次meeting继续讨论程序的问题以及单元测试和集成测试.本次测试为1.00版本.本次的Task列表如下: Task列表 出席人员 Today's Task Tomorrow's Task 刘 ...
- adb 选择设备
在adb中有多个设备时,可以先adb devices列举出设备,然后可以通过adb -s <设备名> [其他参数] 对某个设备进行操作. 例如: adb -s 0123456789ABC ...
- PHP中应用Service Locator服务定位及单例模式
单例模式将一个对象实例化后,放在静态变量中,供程序调用. 服务定位(ServiceLocator)就是对象工场Factory,调用者对象直接调用Service Locator,与被调用对象减轻了依赖关 ...
- UVA 11858 Frosh Week 逆序对统计
题目链接: http://acm.hust.edu.cn/vjudge/contest/122094#problem/H Frosh Week Time Limit:8000MSMemory Limi ...
- ios开发之网络数据的下载与上传
要实现网络数据的下载与上传,主要有三种方式 > NSURLConnection 针对少量数据,使用“GET”或“POST”方法从服务器获取数据,使用“POST”方法向服务器传输数据; > ...
- Codeforces Round #240 (Div. 2)->A. Mashmokh and Lights
A. Mashmokh and Lights time limit per test 1 second memory limit per test 256 megabytes input standa ...
- [设计模式] 1/2 工程与抽象工程模式 factory & Abstrac Factory
转载 http://blog.csdn.net/wuzhekai1985 软件领域中的设计模式为开发人员提供了一种使用专家设计经验的有效途径.设计模式中运用了面向对象编程语言的重要特性:封装.继承.多 ...
- uva 11609
可以想到 答案为 1*C(1,n)+2*C(2,n)+3*C(3,n)+....+n*C(n,n); 由公式 k*C(k,n) = n*C(k-1,n-1) 所以最终答案 n*2^(n-1) 用到快速 ...
- java reflect 例子
public static void main(String[] args) { Student stu1 = new Student(); stu1.setId(1); stu1.setName(& ...