SGU 138 Games of Chess(构造)

题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=138

题意:给定一个比赛每个人下的盘数,构造比赛流程。

思路:将度数降序排序,每个点除最后一个为输外其余都为赢。

#include <iostream>

#include <cstdio>

#include <string.h>

#include <algorithm>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <map>



#define max(x,y) ((x)>(y)?(x):(y))

#define min(x,y) ((x)<(y)?(x):(y))

#define abs(x) ((x)>=0?(x):-(x))

#define i64 long long

#define u32 unsigned int

#define u64 unsigned long long

#define clr(x,y) memset(x,y,sizeof(x))

#define CLR(x) x.clear()

#define ph(x) push(x)

#define pb(x) push_back(x)

#define Len(x) x.length()

#define SZ(x) x.size()

#define PI acos(-1.0)

#define sqr(x) ((x)*(x))



#define FOR0(i,x) for(i=0;i<x;i++)

#define FOR1(i,x) for(i=1;i<=x;i++)

#define FOR(i,a,b) for(i=a;i<=b;i++)

#define DOW0(i,x) for(i=x;i>=0;i--)

#define DOW1(i,x) for(i=x;i>=1;i--)

#define DOW(i,a,b) for(i=a;i>=b;i--)

using namespace std;





void RD(int &x){scanf("%d",&x);}

void RD(i64 &x){scanf("%lld",&x);}

void RD(u64 &x){scanf("%llu",&x);}

void RD(u32 &x){scanf("%u",&x);}

void RD(double &x){scanf("%lf",&x);}

void RD(int &x,int &y){scanf("%d%d",&x,&y);}

void RD(i64 &x,i64 &y){scanf("%lld%lld",&x,&y);}

void RD(u64 &x,u64 &y){scanf("%llu%llu",&x,&y);}

void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}

void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}

void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}

void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}

void RD(u64 &x,u64 &y,u64 &z){scanf("%llu%llu%llu",&x,&y,&z);}

void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}

void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}

void RD(char &x){x=getchar();}

void RD(char *s){scanf("%s",s);}

void RD(string &s){cin>>s;}



void PR(int x) {printf("%d\n",x);}

void PR(i64 x) {printf("%I64d\n",x);}

void PR(u64 x) {printf("%llu\n",x);}

void PR(u32 x) {printf("%u\n",x);}

void PR(double x) {printf("%lf\n",x);}

void PR(char x) {printf("%c\n",x);}

void PR(char *x) {printf("%s\n",x);}

void PR(string x) {cout<<x<<endl;}







int n,a[10005],b[10005],d[105],c[105];



int cmp(int x,int y)

{

    return d[x]>d[y];

}



int main()

{

    RD(n);

    int i,j,s=0;

    FOR1(i,n)

    {

        RD(d[i]);

        s+=d[i];

        c[i]=i;

    }

    sort(c+1,c+n+1,cmp);

    s>>=1;

    PR(s);

    j=1;

    FOR1(i,s)

    {

        if(d[c[j]]==1)

        {

            b[i]=c[j];

            d[c[j]]--;

            j++;

        }

        a[i]=c[j];

        d[c[j]]--;

    }

    FOR1(i,s) if(!b[i])

    {

        if(!d[c[j]]) j++;

        b[i]=c[j],d[c[j]]--;

    }

    FOR1(i,s) printf("%d %d\n",a[i],b[i]);

    return 0;

}

  

你可能感兴趣的:(games)