[SGU]138. Games of Chess

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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值