bzoj1562
很明显是二分图匹配,关键是怎么求字典序最小
想到两种做法,首先是直接匹配,然后从第一位贪心调整
第二种是从最后一个倒着匹配,每次匹配都尽量选小的,这样一定能保证字典序最小
type node=record
po,next:longint;
end; var e:array[..] of node;
p,cx,cy:array[..] of longint;
v:array[..] of boolean;
i,n,len,x,y,s,d:longint; procedure add(x,y:longint);
begin
inc(len);
e[len].po:=y;
e[len].next:=p[x];
p[x]:=len;
end; function dfs(x:longint):longint;
var i,y:longint;
begin
i:=p[x];
while i<> do
begin
y:=e[i].po;
if not v[y] then
begin
v[y]:=true;
if (cy[y]=) or (dfs(cy[y])=) then
begin
cx[x]:=y;
cy[y]:=x;
exit();
end;
end;
i:=e[i].next;
end;
exit();
end; begin
readln(n);
for i:= to n do
begin
read(d);
x:=i+d;
if x>n then x:=x-n;
y:=i-d;
if y< then y:=y+n;
if x>y then
begin
add(i,x);
add(i,y);
end
else begin
add(i,y);
if x<>y then add(i,x);
end;
end;
s:=;
for i:=n downto do
if cx[i]= then
begin
fillchar(v,sizeof(v),false);
s:=s+dfs(i);
end;
if s<n then writeln('No Answer')
else begin
for i:= to n do
begin
write(cx[i]-);
if i<>n then write(' ');
end;
end;
end.
bzoj1562的更多相关文章
- 【bzoj1562】 NOI2009—变换序列
http://www.lydsy.com/JudgeOnline/problem.php?id=1562 (题目链接) 题意 给出一个序列(0~n-1),这个序列经过某个变换会成为另外一个序列,但是其 ...
- 【BZOJ1562】【NOI2009】变换序列(二分图匹配)
[BZOJ1562][NOI2009]变换序列 题面 BZOJ 洛谷 这题面写的是真的丑,还是先手动翻译成人话. 让你构造一个\(0..N-1\)的排列\(T\) 使得\(Dis(i,T_i)\)为给 ...
- [BZOJ1562][ZJOI2007] 最大半连通子图
Description Input 第一行包含两个整数N,M,X.N,M分别表示图G的点数与边数,X的意义如上文所述.接下来M行,每行两个正整数a, b,表示一条有向边(a, b).图中的每个点将编号 ...
- [BZOJ1562][NOI2009] 变换序列
Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30%的数据中N≤50:60%的数据中N≤ ...
- BZOJ1562——[NOI2009]变换序列
1.题意:题意有些难理解 2.分析:我们发现如果要求判断是否合法的话就so easy了,二分图匹配即可,但是我们发现要求输出字典序最小的,那么我们在匈牙利的时候就倒着枚举,另外邻接表中的边一定要排好序 ...
- bzoj1562【Noi2009】变换序列
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1562 给一个序列Di表示min(|i-Ti|,n-|i-Ti|),求一个字典序最小的序列Ti ...
- bzoj1562[NOI2009]变换序列——2016——3——12
任意门:http://www.lydsy.com/JudgeOnline/problem.php?id=1562 题目: 对于0,1,…,N-1的N个整数,给定一个距离序列D0,D1,…,DN-1,定 ...
- BZOJ1562: [NOI2009]变换序列(二分图 匈牙利)
Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30%的数据中N≤50:60%的数据中N≤ ...
- 【bzoj1562】【[NOI2009]变换序列】匈牙利算法的性质利用
(上不了p站我要死了,侵权度娘背锅) Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30 ...
随机推荐
- Careercup - Google面试题 - 4807591515389952
2014-05-06 00:45 题目链接 原题: What would happen if you have only one server for a web cache (a web brows ...
- 【转】如何设置Android软键盘的默认不弹出?
在开发Anroid的时候,当你打开一个界面的时候,屏幕的焦点会自动停留在第一个EditText中,Android的软键盘默认会自动弹出,用户第一眼连界面都没有看清楚,软键盘就弹出来了,这就影响到了用户 ...
- IIS搭建本地服务器,花生壳实现外网通过域名访问网站
配置服务器 作为一个青年,没有实力,做不出标图所示的服务器. 作为一个学生,买不起服务器 作为一个小孩,买不起域名 但别忘了 作为一个平民玩家,只要有耐心 装备迟早会做出来的 (注:感觉有钱与没钱还是 ...
- centos nginx,php添加到Service
SHELL脚本: nginx vim /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx da ...
- FZU 2016 summer train I. Approximating a Constant Range 单调队列
题目链接: 题目 I. Approximating a Constant Range time limit per test:2 seconds memory limit per test:256 m ...
- trie树(前缀树)
问题描述: Trie树,即字典树,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优 ...
- 【设计模式六大原则3】依赖倒置原则(Dependence Inversion Principle)
定义:高层模块不应该依赖低层模块,二者都应该依赖其抽象:抽象不应该依赖细节:细节应该依赖抽象. 问题由来:类A直接依赖类B,假如要将类A改为依赖类C,则必须通过修改类A的代码来达成.这种场景下,类 ...
- Genymotion加载so出错解决方案
通过网上所搜得出结论: Genymotion是x86的架构,而我们的so库是arm架构的 解决:安装Genymotion-ARM-Translation.zip 1.下载:http://pan.bai ...
- 阻止事件冒泡(stopPropagation和cancelBubble)和阻止默认行为(preventDefault和returnValue)
<div id="divId1" style="width:500px;height:500px;background-color:#3ac;text-align: ...
- 李洪强iOS开发支付集成之支付宝支付
iOS开发支付集成之支付宝支付 下载支付宝SDK 首先是开发包下载,还是比较难发现的,网上以前文章中的链接都打不开,我找了好久才找到的.最新的地址在这里(注意的是下载出来的SDK包里面并没有传说中的开 ...