[SGU]138. Games of Chess
来源:互联网 发布:用户行为数据分析 编辑:程序博客网 时间:2024/05/16 12:17
Analysis
又是一道构造题。这道题想了很久没想出来……最后根据网上别人的题解构造了一下就AC了……总的比赛场数为每个人的相加除以二,构造方法是,先把人按比赛场次由多到少排序,然后按这个顺序,把每个人除最后一场外安排为胜场,最后一场为负场,直到胜场全部排完,剩下的人都安排负场。
Accepted Code
var tot,n,i,j,bag,tmp:longint; win,lost,num,a:array[0..10100] of longint;begin readln(n); tot:=0; for i:=1 to n do begin read(a[i]); num[i]:=i; tot:=tot+a[i]; end; tot:=tot shr 1; writeln(tot); for i:=1 to n-1 do for j:=i+1 to n do if a[i]<a[j] then begin tmp:=a[i]; a[i]:=a[j]; a[j]:=tmp; tmp:=num[i]; num[i]:=num[j]; num[j]:=tmp; end; win[1]:=num[1]; j:=1; bag:=1; for i:=2 to tot do begin if bag=a[j]-1 then begin lost[i]:=num[j]; inc(j); bag:=1; win[i]:=num[j]; end else if bag=a[j] then begin inc(j); bag:=1; win[i]:=num[j]; end else begin win[i]:=num[j]; inc(bag); end; end; for i:=1 to tot do begin if lost[i]>0 then continue; if bag=a[j] then begin inc(j); lost[i]:=num[j]; bag:=1; end else begin lost[i]:=num[j]; inc(bag); end; end; for i:=1 to tot do writeln(win[i],' ',lost[i]);end.
- [SGU]138. Games of Chess
- SGU 138 Games of Chess 构造
- SGU 138 Games of Chess(构造)
- sgu138:Games of Chess
- SGU138 Games of Chess
- sgu138: Games of Chess
- sgu 544 Chess Championship
- SGU 536 Berland Chess(状态压缩 + bfs)
- SGU 536 Berland Chess 状态压缩 + BFS
- SGU 536 Berland Chess(状压+BFS)
- the history of video games
- The Sprague-Grundy theory of impartial games
- Best Practice of cross-platform games
- CF 455B-- A Lot of Games
- codeforces 455B. A Lot of Games
- (CF) D. A Lot of Games
- codeforces 455B A Lot of Games
- codeforces 455B A Lot of Games
- php函数的引用参数及参数个数
- Spring的Bean有两种基本行为
- 手工配置hibernate需要的jar包
- UVA699 - The Falling Leaves
- OPNET网络仿真
- [SGU]138. Games of Chess
- 身份证号码规则
- Android开发之适配器ListView
- 仿射变换(Affine Transform)
- 编译OpenCV2.4.3中的OCL模块
- ERROR 1045 (28000): Access denied for user
- Project Euler problem 28
- Spring中的Bean实现的创建三种方式
- ORACLE SQL语句优化技术分析