自己猜测了一下  按比赛次数 从大到小排  然后类似于模拟 先排胜的场次 当只剩一场 将它定义为败

#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;
}

sgu 138的更多相关文章

  1. SGU 138. Games of Chess 构造 难度:2

    138. Games of Chess time limit per test: 0.25 sec. memory limit per test: 4096 KB N friends gathered ...

  2. SGU 138.Games of Chess

    时间限制:0.25s 空间限制:4M 题目: n个朋友在一起按照下面的规则依次下棋:在第一局游戏,n个人中的两个开始下棋.在第二局,第一局胜利的人将跟其他人下棋(也可能还是输了第一局人), 在第三局第 ...

  3. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  4. CF#138 div 1 A. Bracket Sequence

    [#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...

  5. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  6. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  7. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  8. SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...

  9. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

随机推荐

  1. python基础:三层循环

    三层循环基本演示: break_flag = False #标记1 break_flag2 = False #标记2 break_flag3 = False #标记3 while not break_ ...

  2. WAS缓存导致修改文件不生效问题

    当用ftp上传部署增量文件,was应用不生效问题解决方法:一. 修改web.xml文件,需要修改以下三个目录下的文件:1. /opt/IBM/WebSphere/AppServer/profiles/ ...

  3. [转]Linux 分区 swap

    如何合理设置Linux的swap分区 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://commandos.blog.51cto.c ...

  4. ThreadLocal学习记录

    ThreadLocal简介 当使用ThreadLocal维护变量时,ThreadLocal为每个使用该变量的线程提供独立的变量副本,所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的 ...

  5. 老式浏览器兼容HTML5和CSS3的问题

      1.让老式浏览器支持HTML5   HTML5能为我们做的事儿很多,最为可口的就是语义化标签的应用,如果你已经在Chrome或者其他支持HTML5的浏览器上用过它的牛x,那这篇文章对你一定有用,因 ...

  6. jquery.min.map详见

    温故而知新,翻出来阮前辈的文章记录一下 日期:2013年1月23日 上周,jQuery 1.9发布. 这是2.0版之前的最后一个新版本,有很多新功能,其中一个就是支持Source Map. 访问 ht ...

  7. 关于PHP Websocket 错误: "stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE" 的解决方案

    最近在使用Ratchet (一个PHP websocket框架)改造一个PHP网站的时候,出现了错误: "It is set to 1024, but you have descriptor ...

  8. IDEA笔记

    快捷键: 查找类:ctrl + shif + R (eclipse)查找文件:double shift查找文件中的变量名和方法:ctrl + H (eclipse)system.out:输入 sout ...

  9. PHP获取当前日期或指定日期的所在月的第一天和最后一天

    <?php function getthemonth($date) { $firstday = date('Y-m-01', strtotime($date)); $lastday = date ...

  10. HTML5的页面资源预加载技术(Link prefetch)加速页面加载

    不管是浏览器的开发者还是普通web应用的开发者,他们都在做一个共同的努力:让Web浏览有更快的速度感觉.有很多已知的技术都可以让你的网站速度变得更快:使用CSS sprites,使用图片优化工具,使用 ...