很明显是二分图匹配,关键是怎么求字典序最小

想到两种做法,首先是直接匹配,然后从第一位贪心调整

第二种是从最后一个倒着匹配,每次匹配都尽量选小的,这样一定能保证字典序最小

 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的更多相关文章

  1. 【bzoj1562】 NOI2009—变换序列

    http://www.lydsy.com/JudgeOnline/problem.php?id=1562 (题目链接) 题意 给出一个序列(0~n-1),这个序列经过某个变换会成为另外一个序列,但是其 ...

  2. 【BZOJ1562】【NOI2009】变换序列(二分图匹配)

    [BZOJ1562][NOI2009]变换序列 题面 BZOJ 洛谷 这题面写的是真的丑,还是先手动翻译成人话. 让你构造一个\(0..N-1\)的排列\(T\) 使得\(Dis(i,T_i)\)为给 ...

  3. [BZOJ1562][ZJOI2007] 最大半连通子图

    Description Input 第一行包含两个整数N,M,X.N,M分别表示图G的点数与边数,X的意义如上文所述.接下来M行,每行两个正整数a, b,表示一条有向边(a, b).图中的每个点将编号 ...

  4. [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≤ ...

  5. BZOJ1562——[NOI2009]变换序列

    1.题意:题意有些难理解 2.分析:我们发现如果要求判断是否合法的话就so easy了,二分图匹配即可,但是我们发现要求输出字典序最小的,那么我们在匈牙利的时候就倒着枚举,另外邻接表中的边一定要排好序 ...

  6. bzoj1562【Noi2009】变换序列

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1562 给一个序列Di表示min(|i-Ti|,n-|i-Ti|),求一个字典序最小的序列Ti ...

  7. bzoj1562[NOI2009]变换序列——2016——3——12

    任意门:http://www.lydsy.com/JudgeOnline/problem.php?id=1562 题目: 对于0,1,…,N-1的N个整数,给定一个距离序列D0,D1,…,DN-1,定 ...

  8. 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≤ ...

  9. 【bzoj1562】【[NOI2009]变换序列】匈牙利算法的性质利用

    (上不了p站我要死了,侵权度娘背锅) Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30 ...

随机推荐

  1. iOS 下拉菜单 FFDropDownMenu自定义下拉菜单样式实战-b

    Demo地址:https://github.com/chenfanfang/CollectionsOfExampleFFDropDownMenu框架地址:https://github.com/chen ...

  2. 将Xml字符串转换成(DataTable || DataSet || XML)对象

    今天用到一个功能:就是把从数据库读出来的内容转换成XML字符串流格式,并输出给一个功能函数.在写的过程,为方便以后的使用,我对这一功能进行分装.该类的具体格式如下:XmlConvert类命名空间:Ni ...

  3. SQL获取数据库名,表名,列名,说明等信息

    由于最近工作涉及SQL语句较多,对一些不常见的SQL函数.及存储过程下面进行整理和描述,供大家分享: /************************************************ ...

  4. 2433: [Noi2011]智能车比赛 - BZOJ

    Description 新一届智能车大赛在JL大学开始啦!比赛赛道可以看作是由n个矩形区域拼接而成(如下图所示),每个矩形的边都平行于坐标轴,第i个矩形区域的左下角和右上角坐标分别为(xi,1,yi, ...

  5. HtmlAgilityPack 简单运用

    WebClient client = new WebClient(); MemoryStream ms = new MemoryStream(client.DownloadData("htt ...

  6. java.lang.NullPointerException&com.cb.action.LoginAction.execute(LoginAction.java:48)

    今天做一个Spring和Struts的融合,通过bean注入后,程序一跑起来,就报这个错误: java.lang.NullPointerException com.cb.action.LoginAct ...

  7. catci监控

    snmp安装:yum install net-snmp* 配置/etc/snmp/snmpd.conf:com2sec notConfigUser 192.168.79.129    publicac ...

  8. MySQL性能优化的最佳20+条经验(转)

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我 们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数 ...

  9. Eclipse下PHP开发 插件安装

    PHPeclipse是什么? PHPeclipse是Eclipse的一个插件,它为php开发人员提供了一个集成的开发环境.Eclipse官方下载地址:http://www.eclipse.org/ P ...

  10. mac os 下如何清除/切换svn eclipse插件的用户

    以mac os x为例(Unix/Linux类似), 1.打开命令行窗口,即用户的根目录(用户的home目录) $ ls -al ... drwxr-xr-x   6 linxyz  staff   ...