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

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

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

 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. SCRUM报告(一)

    我们“来用”团队确定的PM是邓锐.这是我们第一篇SCRUM报告,报告的内容就是我们的Sprint会议.之前冲刺计划会议的内容已发博客,这里简单阐述一下. 一.会议过程大致如下: 1.总结目前的工作进展 ...

  2. android 自定义ratingbar 图片显示不全的解决方案

    在res/style中自定义评分条: <!-- 自定义评分条 --> <style name="roomRatingBar" parent="@andr ...

  3. CSS进阶

    盒子模型的边框就是围绕着内容及补白的线,这条线你可以设置它的粗细.样式和颜色(边框三个属性). 1.border-style(边框样式)常见样式有:dashed(虚线)| dotted(点线)| so ...

  4. ora-28002 the password will expire解决办法

    Oracle11g R2数据库提示ORA-28002: the password will expire within 5 days,是说密码过期,将Oracle密码设置成永不过期就可以了,不过并不推 ...

  5. cookieContainer应用

    PublicSharedFunctionGetCookiesSetByPage(ByVal strUrl AsString,ByVal cookieToProvide AsString)AsIEnum ...

  6. PHP对XML文件操作类讲解

    <?phpclass XML{    private $dom;        function __construct ()    {        $this->dom = new D ...

  7. 01-06-01【Nhibernate (版本3.3.1.4000) 出入江湖】事务

    Nhibernate事务的使用: public void Add(Customer customer) { ISession session = _sessionManager.GetSession( ...

  8. Guava文档翻译之ListenableFuture

    ListenableFutureExplained 并发是一个困难的问题,但是使用强大而简单的抽象可以极大地简化并发问题.为了简化事情,Guava使用ListenableFuture继承了JDK的Fu ...

  9. HDU 3461 Code Lock(并查集,合并区间,思路太难想了啊)

    完全没思路,题目也没看懂,直接参考大牛们的解法. http://www.myexception.cn/program/723825.html 题意是说有N个字母组成的密码锁,如[wersdfj],每一 ...

  10. Linux防火墙(Iptables)的开启与关闭

    Linux防火墙(iptables)的开启与关闭 Linux中的防火墙主要是对iptables的设置和管理. 1. Linux防火墙(Iptables)重启系统生效 开启: chkconfig ipt ...