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 ...
随机推荐
- 低压差稳压器AMS1585
(1)高效线性稳压. (2)输出高达4.6A,最高输入电压15V,推荐最低压差1.5V(最低1.35V),最大压差12V. (3)两种封装:TO220(直插式),TO230(贴片). 典型电路如下图所 ...
- HDOJ(HDU) 4847 Wow! Such Doge!(doge字符统计)
Problem Description Chen, Adrian (November 7, 2013). "Doge Is An Ac- tually Good Internet Meme. ...
- php 中 global 与 $GLOBAL 由引用产生的区别
很多人都认为global和$GLOBALS[]只是写法上面的差别,其实不然. 根据官方的解释是 $GLOBALS['var'] 是外部的全局变量$var本身. global $var 是外部$var的 ...
- (java) Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * Lis ...
- 深入hibernate的三种状态【转载】
这篇文章写得很好,举了很多例子. http://www.cnblogs.com/xiaoluo501395377/p/3380270.html
- zabbix oracle监控插件orabbix部署安装
1,下载orabbix插件包(插件包同时满足在大部分POSIX-linux及unix和大部分版本的windows下运行,玩转类似但不等同于Tomcat) wget http://www.smartma ...
- poj 3687 Labeling Balls【反向拓扑】
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12246 Accepted: 3508 D ...
- wind安装selenium
1.按win+r进入运行模式,然后输入cmd进入命令行 2.输入pip按回车 查看命令帮助 3.然后输入pip install selenium 按回车,然后等待 下载,下载好了会自动安装完成 3.然 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(6)-Unity 2.x依赖注入by运行时注入[附源码]
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(6)-Unity 2.x依赖注入by运行时注入[附源码] Unity 2.x依赖注入(控制反转)IOC,对 ...
- c++拷贝构造函数(深拷贝,浅拷贝)详解
一.什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: ; int b=a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量. 下面 ...