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 的时间检查整个打出来的字符串,并且 ...
随机推荐
- 4月12日学习笔记——jQuery事件
下面是在 jQuery 中最常使用的 bind()方法举例:$("#testDiv4").bind("click", showMsg); 我们为 id 是 te ...
- http: URL、请求方式
URL:统一资源定位符,可以从互联网得到和访问资源,是标准资源的位置 结构包括协议.服务器名称(IP地址).端口(有的服务器需要).路径.文件名 协议:告诉浏览器如何处理打开的文件,常用的就是http ...
- String中重要方法与字段
下列这段代码已全部包含了我要写的String类中重要的字段: //StringMisc.java// This program demonstrates the length, charAt and ...
- JSP_EL使用
JSP中EL表达式的简单介绍和使用 参考资料: http://www.java3z.com/cwbwebhome/article/article8/8124.html?id=2453 http ...
- 隐藏虚拟键盘,解决键盘挡住UITextField问题
再正式开始之前,先来介绍一下IOS的键盘类型: 一.键盘风格 UIKit框架支持8种风格键盘 ? 1 2 3 4 5 6 7 8 9 10 typedef enum { UIKeyboard ...
- Windows Phone 中查找可视化树中的某个类型的元素
private void StackPanel_Tap(object sender, TappedRoutedEventArgs e) { //获取到的对象是ListBoxItem ListBoxIt ...
- mycat1.5~1.6的一个bug
以下语句在mysql单库中执行正常: SELECT * FROM device WHERE devicetype='AMS.Monitoring.XlCloud.QKL8154.XLCloudDevi ...
- zedboard - 轻量级以太网控制器LWIP
ipconfig/all route print 显示本机所有的网络 网关是什么 那么网关到底是什么呢?网关实质上是一个网络通向其他网络的IP地址.比如有网络A和网络B,网络A的IP地址范围为&qu ...
- (转)Jmeter内存溢出处理方式记录
方法一: 使用jmeter进行压力测试时 遇到一段时间后报内存溢 出outfmenmory错误,导致jmeter卡死了,先尝试在jmeter.bat中增加了JVM_ARGS="- Xmx20 ...
- ORACLE 语句关联统计
很久不用SQL语句了,貌似入职新公司后,又回归到了三年前的SQL时代,一写一坨的SQL好吧,也当回归一下过去的知识. 下面是统计2月份某数据的计费统计 select t.telno as 主号,VID ...