noip2005篝火晚会 2008.10.18
来源:互联网 发布:阿里云如何域名解析 编辑:程序博客网 时间:2024/04/28 12:18
noip2005篝火晚会 2008.10.18
注意:
1. 刚开始,我用的是图来标记这两个人是否已经输出过,一直出错,后来看了标称,方法很好
2. 求出序列后,因为是圆环,要正着求一次差,求相同的最大值,还要倒着求一次差,求最大值,这样才圆满,我只正着求了,故一直出错
3. 不能用abs,若剪出的结果是负数,应加上n;标称的处理方法很好,相减后+n,再mod n
Program:
program noip2005_3; const maxn=50000; var n:longint; tm,w:array[0..maxn] of longint; g:array[1..maxn,0..4] of longint; function solve(x,y:longint):boolean; var i:integer; begin solve:=true; for i:=1 to g[x,0] do if y=g[x,i] then exit(false); end;{判断两个人以前是否出现过} procedure init; var i,x,y:longint; begin readln(n); for i:=1 to n do begin read(x,y); if solve(i,x) then begin inc(g[x,0]); g[x,g[x,0]]:=i; inc(g[i,0]); g[i,g[i,0]]:=x end; if solve(i,y) then begin inc(g[y,0]); g[y,g[y,0]]:=i; inc(g[i,0]); g[i,g[i,0]]:=y; end; if (g[x,0]>2) or (g[y,0]>2) then begin writeln(-1); close(input); close(output); halt end;{不必读完,出现问题,不再读他,就跳出} end; end; procedure ready; var i,j:longint; begin tm[0]:=0; tm[1]:=1; for i:=2 to n do for j:=1 to g[tm[i-1],0] do if g[tm[i-1],j]<>tm[i-2] then tm[i]:=g[tm[i-1],j]; end; procedure main; var i,j,max,ans:longint; begin max:=0; for i:=1 to n do inc(w[ (tm[i]+n-i) mod n ]); for i:=0 to n-1 do if w[i]>max then max:=w[i]; fillchar(w,sizeof(w),0); for i:=n downto 1 do inc(w[ (tm[i]+n-(n-i+1)) mod n ]); for i:=0 to n-1 do if w[i]>max then max:=w[i]; ans:=n-max; writeln(ans); end; begin assign(input,'fire.in'); assign(output,'fire.out'); reset(input); rewrite(output); init; ready; main; close(input); close(output); end.
0 0
- noip2005篝火晚会 2008.10.18
- 【模拟】篝火晚会(noip2005)
- NOIP2005 篝火晚会
- NOIP2005篝火晚会
- NOIP2005 篝火晚会
- [codevs1106][NOIP2005]篝火晚会
- noip2005 篝火晚会 (模拟)
- 洛谷 P1053 [NOIP2005 T3] 篝火晚会
- [NOIP2005][CODEVS1106]篝火晚会(模拟+数学相关)
- 【NOIP2005提高组T3】篝火晚会-置换群
- noip2005提高组篝火晚会 && nyoj59题小明活动的组织任务
- 篝火晚会 题解
- VIJOS 1008 篝火晚会
- Vijos1008 篝火晚会
- Codevs 1106 篝火晚会
- RQNOJ 篝火晚会
- RQNOJ-19 篝火晚会
- P1053 篝火晚会
- Java SE 7 中带资源声明的 try 语句(try-with-resources statement)
- SharePoint2016 New Feature (Preview) - 支持ODF File Template
- OpenGL编程指南之阅读笔记 第二章 状态管理和绘制几何物体
- 跟我学汇编(一)基础知识
- hadoop2.5.2安装部署
- noip2005篝火晚会 2008.10.18
- SQL Server远程连接
- 自己写的js插件,grid/lookup等,留存参考
- Oracle锁表进程解锁
- 【C/S】——浅谈AppSettings和ConnectionStrings的区别
- [BZOJ 2301] HAOI 2011 Problem b · 莫比乌斯
- Growth发布iOS版 — 距今为止最好的开源“Web开发学习”应用
- Hadoop完全分布式集群安装(Ubuntu)
- 车联网API——位置、距离