SGU 138 Games of Chess 构造
来源:互联网 发布:网络报案中心我要报案 编辑:程序博客网 时间:2024/05/17 09:36
题目链接点这儿
很容易yy出来一个构造方式
比赛次数明显为sum/2(sum是每人出厂次数之和)
先按出场次数排序,然后从大到小依次填充。
构造形如
winner a a a a a a b b b b b c c c ……
loser b c d
这样的形状,然后把败者空着的地方填充,很容易证明,这样不会有winner和loser同为一个人的情况。
代码如下
#include <bits/stdc++.h>#define up(i, lower, upper) for(int i = lower; i < upper; i++)#define down(i, lower, upper) for(int i = upper-1; i >= lower; i--)using namespace std;typedef pair<int, int> pii;typedef pair<double, double> pdd;typedef vector<int> vi;typedef vector<pii> vpii;typedef long long ll;typedef unsigned long long ull;const double pi = acos(-1.0);const double eps = 1.0e-9;template<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}template <class T>inline void write(T n) { if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48);}///---------------------------------------------------------struct node { int num, cnt; node() :cnt(0) {} friend bool operator < (node a, node b){ return a. cnt > b. cnt; }};node a[101];int winner[10001], loser[10001];int main() { int n; read(n); up(i, 1, n+1) a[i].num = i; int sum = 0; up(i, 1, n+1) { read(a[i].cnt); sum += a[i].cnt; } sort(a+1, a+n+1); sum /= 2; int pt = 1; up(i, 0, sum) { if(a[pt].cnt>1) winner[i] = a[pt].num, a[pt].cnt--; else { loser[i] = a[pt].num, a[pt].cnt--; while(a[pt].cnt <= 1) pt++; winner[i] = a[pt].num, a[pt].cnt--; } } pt = 1; up(i, 0, sum) { if(!loser[i]) { while(a[pt].cnt < 1) pt++; loser[i] = a[pt].num, a[pt].cnt--; } } write(sum); puts(""); up(i, 0, sum) printf("%d %d\n", winner[i], loser[i]);}
0 0
- SGU 138 Games of Chess 构造
- SGU 138 Games of Chess(构造)
- [SGU]138. Games of Chess
- sgu138:Games of Chess
- SGU138 Games of Chess
- sgu138: Games of Chess
- sgu 544 Chess Championship
- 【SGU】109. Magic of David Copperfield II 构造
- SGU 109 Magic of David Copperfield II(构造)
- SGU 109 Magic of David Copperfield II(构造)
- SGU 536 Berland Chess(状态压缩 + bfs)
- SGU 536 Berland Chess 状态压缩 + BFS
- SGU 536 Berland Chess(状压+BFS)
- SGU 361 (构造)
- the history of video games
- sgu 165 Basketball 贪心构造
- SGU 191 Exhibition (贪心+构造)
- SGU 138
- 当心甜食“中毒” 几个饮食控制血糖的秘密
- 播放器(FZU 2091)
- 验证素数(素数筛选法验证素数)
- hdu 2544 最短路(图论:迪杰斯特拉||弗洛伊德算法)
- JVM的垃圾回收机制详解和调优
- SGU 138 Games of Chess 构造
- jquery 取子节点及当前节点属性值
- 继承(2)
- 1069: [SCOI2007]最大土地面积
- IoT 解释
- 游戏运营笔记四数据分析
- poj2485
- 消息队列自结
- Java compiler level does not match the version of the installed Java project facet.