SGU 138.Games of Chess
时间限制: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的更多相关文章
- 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 ...
- sgu 138
自己猜测了一下 按比赛次数 从大到小排 然后类似于模拟 先排胜的场次 当只剩一场 将它定义为败 #include <cstdio> #include <cstdlib> # ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 绿色 或者 免安装 软件 PortableApps
Refer to http://portableapps.com/apps for detail. Below is just a list at Jan-01-2017 for quick show ...
- (转) Artificial intelligence, revealed
Artificial intelligence, revealed Yann LeCunJoaquin Quiñonero Candela It's 8:00 am on a Tuesday morn ...
- (转) Deep Learning Research Review Week 2: Reinforcement Learning
Deep Learning Research Review Week 2: Reinforcement Learning 转载自: https://adeshpande3.github.io/ad ...
- Chinese culture
文房四宝 笔墨纸砚是中国古代文人书房中必备的宝贝,被称为“文房四宝”.用笔墨书写绘画在 中国可追溯到五千年前.秦(前221---前206)时已用不同硬度的毛和竹管制笔:汉代(前206—公元220) ...
- TED - How To Get Better At The Things You Care About
TED01 - How To Get Better At The Things You Care About 昨天我发布了攻克英语口语的宣言,今天就行动.TED是我们学习口语的好地方,本着学以致用的原 ...
- [转]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 ...
随机推荐
- 汇编学习笔记(11)int指令和端口
格式 int指令也是一种内中断指令,int指令的格式为int n,n是中断类型码.也就是说,使用int指令可以调用任意的中断例程,例如我们可以显示的调用0号中断例程,还记得在汇编学习笔记(10)中我们 ...
- Matlab编程-基本命令行语句
(1) mathlab命令行中“,”与“:”的区别: 结尾不加任何东西也会输出结果 以“,”结尾不显示变量数值,但是再次输入变量名之后可以输出变量值 以“:”结尾显示变量值 (2) 输出格式控制 ...
- xapian搜索系统存储结构解读
Xapian的database是所有用于检索的信息表的集合,以下的表是必需的: posting list table 保存了被每一个term索引的document,实际上保存的应该是document在 ...
- hdu 4432 Sum of divisors(十进制转其他进制)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4432 代码: #include<cstdio> #include<cstring&g ...
- arm 及ndk编译
首页 » Android android的armeabi跟armeabi-v7a 网友分享于:2014-03-16 浏览:867次 android的armeabi和armeabi-v7 ...
- pecl/mongo is already installed
sw-engine-cgi PHP MongoDB database drivermongodb database driver,数据库驱动;
- 使用ECharts报表统计公司考勤加班,大家加班多吗?
最近个项目已经连续加班1个月多,因为公司经常有在外面客户现场或出差的情况,人事每个月初会把上个月的份考勤打卡记录全部发出来,让我们对自己的考勤,突然想到可根据大家打卡时间记录统计每天工作时间,看大家是 ...
- C —— 零碎笔记
1.字节对齐和结构体大小 链接 2.共同体union 的作用 链接 3.文件夹和文件操作 windows: http://blog.csdn.net/gneveek/article/details/6 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(28)-系统小结
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(28)-系统小结 我们从第一节搭建框架开始直到二十七节,权限管理已经告一段落,相信很多有跟上来的园友,已经 ...
- Notepad++中的复活节彩蛋(easter egg)
Notepad++是windows下的一个强大的文本编辑器; 它免费,开源, 比windows自带的记事本强大百倍; 我自己的感觉: 1.打开超大的文本文件,比方100M大小的文本格式的数据,记事本会 ...