时间限制:0.25s 空间限制:4M 题目:

    n个朋友在一起按照下面的规则依次下棋:在第一局游戏,n个人中的两个开始下棋。在第二局,第一局胜利的人将跟其他人下棋(也可能还是输了第一局人),
在第三局第二局的胜利者将跟其他人下...依此类推。没有棋局将以平局结束,给出n个人参加过的的棋局的编号,找到一个安排棋局的方法,满足上面的规则。

输入

   第一行一个整数n(2<=n<=100).第二行有n个数,代表这n个人参加的棋局次数.

输出

   第一行是总共进行的棋局的数目k.
接下来k行是,各个棋局参加的人的编号,要求胜利的人在前面

Sample Input

4
2 4 1 5

Sample Output

6
4 3
4 1
2 4
2 1
4 2
2 4

Solution:
因为两个可以重复对局,随便构造,按赢的场次排,对每一场从winer开排,排玩winer排loser 参考代码:
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, sum, cnt[101], pos[101];
int win[10001], lose[10001];
bool cmp (int a, int b){
return (cnt[a] > cnt[b]);
}
int main(){
scanf ("%d", &n);
for (int i = 1; i <= n; ++i){
scanf ("%d", &cnt[i]);
sum += cnt[i];
pos[i] = i;
}
sum /= 2;
sort (pos + 1, pos + n + 1, cmp);
int j = 1;
for (int i = 1; i <= sum; ++i){
if (cnt[pos[j]] == 1){
lose[i] = pos[j];
cnt[pos[j++]]--;
}
win[i] = pos[j];
cnt[pos[j]]--;
}
for (int i = 1; i <= sum; ++i){
if (lose[i]) continue;
if (!cnt[pos[j]]) j++;
lose[i] = pos[j];
cnt[pos[j]]--;
}
printf ("%d\n", sum);
for (int i = 1; i <= sum; ++i)
printf ("%d %d\n", win[i], lose[i]);
return 0;
}

  

 

SGU 138.Games of Chess的更多相关文章

  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

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

  3. SGU 分类

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

  4. 绿色 或者 免安装 软件 PortableApps

    Refer to http://portableapps.com/apps for detail. Below is just a list at Jan-01-2017 for quick show ...

  5. (转) Artificial intelligence, revealed

    Artificial intelligence, revealed Yann LeCunJoaquin Quiñonero Candela It's 8:00 am on a Tuesday morn ...

  6. (转) Deep Learning Research Review Week 2: Reinforcement Learning

      Deep Learning Research Review Week 2: Reinforcement Learning 转载自: https://adeshpande3.github.io/ad ...

  7. Chinese culture

      文房四宝 笔墨纸砚是中国古代文人书房中必备的宝贝,被称为“文房四宝”.用笔墨书写绘画在 中国可追溯到五千年前.秦(前221---前206)时已用不同硬度的毛和竹管制笔:汉代(前206—公元220) ...

  8. TED - How To Get Better At The Things You Care About

    TED01 - How To Get Better At The Things You Care About 昨天我发布了攻克英语口语的宣言,今天就行动.TED是我们学习口语的好地方,本着学以致用的原 ...

  9. [转]How rival bots battled their way to poker supremacy

    How rival bots battled their way to poker supremacy http://www.nature.com/news/how-rival-bots-battle ...

随机推荐

  1. 串口传输文件 lrzsz

    假设有一种开发环境,一块板子,除了串口,没有任何外部出入输出设备,没有sd卡,没有网线,这个时候如果你想跟这块板子传输交互文件,要怎么办? 根据modem所采用的文件传输协议:xmodem,ymode ...

  2. 网络流(费用流)CodeForces 321B:Ciel and Duel

    Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: ...

  3. Java-Iterator的用法

    迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭代器通常被称为“轻量级”对象,因为创建它的代价小. Java中的I ...

  4. cocos2d的安装

    安装cocos2d其实就是在Xcode中安装几个模板,然后在Xcode里面就可以直接使用这些模板了. 其实说是模板,也就是封装了许许多多引擎的文件,相对于原生的程序,也许使用引擎模板更加方便.   下 ...

  5. awk替换第几行第几列的值

    代码如下: awk '{if(2==NR){gsub(/.*/, 300, $5)}print}' list.txt 将文件list.txt的第2行第5列的值替换为300

  6. jsp文件中的alert等等

    <script type="text/javascript"> alert("aa: ${message}") </script>

  7. openStack 性能开测

  8. Counting - SGU 117(快速幂)

    题目大意:求下面N个数里面有多少个数的M次方能整除K 代码如下: ======================================================== #include&l ...

  9. 善用VS中的Code Snippet来提高开发效率 分类: C# 2015-01-22 11:06 69人阅读 评论(0) 收藏

    前言  在谈谈VS中的模板中,我介绍了如何创建项目/项模板,这种方式可以在创建项目时省却不少重复性的工作,从而提高开发效率.在创建好了项目和文件后,就得开始具体的编码了,这时又有了新的重复性工作,就是 ...

  10. 使用javah生成.h文件, 出现无法访问android.app,Activity的错误的解决

    在工程ndk22/bin/classes中 运行javah  com.cn.ndk22.Ndk22.Activity ,出现了.h文件 我在bin/classes目录中 ,就是无法访问, : 错误:无 ...