自己猜测了一下 按比赛次数 从大到小排 然后类似于模拟 先排胜的场次 当只剩一场 将它定义为败
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 100010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; struct node
{
int id, x;
bool operator < (const node& p) const
{
return x > p.x;
}
};
node pp[110];
int win[maxn], lose[maxn]; void solve(int sum)
{
int j = 0;
for(int i =0 ; i < sum; ++ i)
{
while(!pp[j].x) j++;
if(pp[j].x > 1)
{
win[i] = pp[j].id;
pp[j].x--;
}
else if(pp[j].x == 1)
{
lose[i] = pp[j].id;
pp[j].x--;
j++;
win[i] = pp[j].id;
pp[j].x--;
}
}
j = 0;
for(int i =0 ; i < sum; ++ i)
{
if(lose[i]) continue;
while(!pp[j].x) j++;
if(pp[j].x > 1)
{
lose[i] = pp[j].id;
pp[j].x--;
}
else if(pp[j].x == 1)
{
lose[i] = pp[j].id;
pp[j].x--;
j++;
}
}
} int main()
{
int n;
while(scanf("%d", &n) == 1)
{
int sum = 0;
for(int i = 0; i < n; ++ i)
{
scanf("%d", &pp[i].x);
pp[i].id = i+1;
sum += pp[i].x;
}
sort(pp, pp+n);
memset(win, 0, sizeof(win));
memset(lose, 0, sizeof(lose));
sum /= 2;
solve(sum);
printf("%d\n", sum);
for(int i = 0; i < sum; ++ i)
printf("%d %d\n", win[i], lose[i]);
}
return 0;
}