sgu 138
自己猜测了一下 按比赛次数 从大到小排 然后类似于模拟 先排胜的场次 当只剩一场 将它定义为败
#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的更多相关文章
- 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.Games of Chess
时间限制:0.25s 空间限制:4M 题目: n个朋友在一起按照下面的规则依次下棋:在第一局游戏,n个人中的两个开始下棋.在第二局,第一局胜利的人将跟其他人下棋(也可能还是输了第一局人), 在第三局第 ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- CF#138 div 1 A. Bracket Sequence
[#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- 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 ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
随机推荐
- Qt 5 在Windows下 出现QApplication: No such file or directory 问题的解决办法
解决方法是:在*.pro工程项目文件中添加一行QT += widgets,然后再编译运行就OK了.
- WordPress使用360CDN替换google服务,解决WordPress打开速度变慢问题
由于wordpress新版本中默认使用了一些google服务及google字体,由于google在天朝中的一些你懂的原因,造成wordpress在打开时被拖慢,这时可以用360推出的公共库CDN服务替 ...
- FIR滤波器(1)- 基础知识
FIR滤波器广泛应用于数字信号处理中,主要功能就是将不感兴趣的信号滤除,留下有用信号.FIR滤波器是全零点结构,系统永远稳定:并且具有线性相位的特征,在有效频率范围内所有信号相位上不失真.在无线通信收 ...
- silverlight webclient实现上传、下载、删除、读取文件
1.上传 private void Button_Click_1(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = ...
- php生成圆形图片
http://files.cnblogs.com/files/adtuu/circle_image.zip
- Lua 常用的shell命令
lua作为一种小巧的脚本语言,其函数等动作可以使用shell命令进行运行和调试,以下是几个常用的shell命令.基本格式是 lua [选项参数] [脚本参数] (1)%lua 程序名.lua ...
- poj 3740 Easy Finding 二进制压缩枚举dfs 与 DLX模板详细解析
题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 ...
- GDB调试详解
GDB是一个由GNU开源组织发布的.UNIX/LINUX操作系统下的.基于命令行的.功能强大的程序调试工具. GDB中的命令固然很多,但我们只需掌握其中十个左右的命令,就大致可以完成日常的基本的程序调 ...
- vc2005 编译ACE-6.2.0
vc2005 编译ACE-6.2.0 下载并解压ACE-6.2.0 ftp://download.dre.vanderbilt.edu/previous_versions/ACE-6.2.0.zip ...
- 深入理解ThreadLocal(二)
3 InheritableThreadLocal的使用 通过上面的分析知道通过ThreadLocal保存的值是线程隔离的.其实在Thread对象中,还有一个ThreadLocal.ThreadLoca ...