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 ...
随机推荐
- Solr -- Solr Facet 1
一.Facet介绍 solr facet 是solr搜索的一大特色,facet不好翻译,有说是垂直搜索,有说是分片搜索,但都不是很好,还是懒得翻译了,就叫facet ,具体功能看下面的例子意会吧. 比 ...
- php5.4下安装ECshop出现错误的解决办法
转:http://www.programmernote.com/?p=65 1.安装是会提示 Warning: date_default_timezone_get(): It is not safe ...
- jqGrid简单介绍
一.要引用的文件 要使用jqGrid,首先页面上要引入如下css与js文件. 1.css <link href="/css/ui.jqgrid.css" rel=" ...
- Delphi 调试WEBService程序(ISAPI或CGI) 把Web App Debugger executable转换成 ISAPI/NSAPI
1.新建一个web工程,请选中最下面一项:Web App Debugger executable,Coclass name我们设为demo1: 2.在弹出的WebModule2中右击,在弹出的Ac ...
- ubuntu安装jdk1.8
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-i ...
- Java---基于TCP协议的相互即时通讯小程序
这是几年前,新浪的一个面试题~要求是3天之内实现~ 通过TCP 协议,建立一个服务器端. 通过配置服务器端的IP和端口: 客户端之间就可以相互通讯~ 上线了全部在线用户会收到你上线的通知. 下线了全部 ...
- JavaScript 兼容处理IE67之 !"a"[0]
IE67对字符串进行取值需要使用charAt()方法,不能直接通过数组方式的坐标访问: <!DOCTYPE html> <html> <head> <meta ...
- CPP变量参数别名
1,变量起"绰号"的操作称为引用(reference),"绰号"称为引用名,申明引用的语法格式; 变量数据类型 &引用名 = 已申明的变量名; 和C中的 ...
- Getting Started · Building a RESTful Web Service
Getting Started · Building a RESTful Web Service undefined
- DOM方法
DOM常用方法: 方法 描述 getElementById() 返回带有指定 ID 的元素. getElementsByTagName() 返回包含带有指定标签名称的所有元素的节点列表(集合/节点数组 ...