CodeForces 370C
这道题其实是挺简单的。首先很容易发现最多人用的颜色的人数如果大于n/2,就肯定不能让全部人都成功戴上两只不同颜色的手套。反过来想,如果这个人数小于等于n/2又如何呢?的确,这就能让全部人都能戴上两只不同颜色的手套(每个人都留一只自己原本的,再要别人的一只手套就可以了)。
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <list>
using namespace std;
struct Child{
int color, num, mat;
};
bool partition_cmp(const Child& c1, const Child& c2){
return c1.color < c2.color;
}
bool sort_cmp(const Child& c1, const Child& c2){
return c1.num < c2.num;
}
int main(){
int n, m;
Child a[];
int c[];
cin >> n >> m;
for (int i = ; i <= m; i++){
c[i] = ;
}
for (int i = ; i < n; i++){
cin >> a[i].color;
a[i].num = i;
c[a[i].color]++;
}
int mx = ;
for (int i = ; i <= m; i++){
if (c[mx] < c[i]){
mx = i;
}
}
if (c[mx] * > n){
cout << * (n - c[mx]) << endl;
int mcount = , miter = -, d = n - c[mx];
for (int i = ; i < n; i++){
if (a[i].color == mx){
cout << a[i].color << " ";
if (d > ){
for (miter++; miter < n && a[miter].color == mx; miter++);
cout << a[miter].color << endl;
d--;
}
else{
cout << a[i].color << endl;
}
}
else{
cout << a[i].color << " " << mx << endl;
}
}
}
else{
cout << n << endl;
sort(a, a + n, partition_cmp);
for (int i = ; i < n; i++){
a[i].mat = a[(i + c[mx]) % n].color;
}
sort(a, a + n, sort_cmp);
for (int i = ; i < n; i++){
cout << a[i].color << " " << a[i].mat << endl;
}
}
return ;
}
CodeForces 370C的更多相关文章
- 【codeforces 370C】Mittens
[题目链接]:http://codeforces.com/problemset/problem/370/C [题意] 给你n个人,每个人都有一双相同颜色的手套; 然允许在所有人之间交换手套; (每个人 ...
- CodeForces 370C. Mittens
C. Mittens time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- python re的使用
re 正则表达式操作 本模块提供了类似于Perl的正则表达式匹配操作.要匹配的模式和字符串可以是Unicode字符串以及8位字符串. 正则表达式使用反斜杠字符('\')来表示特殊的形式或者来允许使用 ...
- VF 查表
题目的意思就是 给你一个数字 n (1~81) 然后问你从 1~10^9 之中有多少个 各位数字之和等于 n 的 数字 我上去 打表了 而且速度还差不多 , 能在 几十分钟内算出来所有答案 ...
- 一个完整的mybatis项目,包含增删改查
1.导入jar包,导入相关配置文件,均在自己博客园的文件中 编写mybatis.xml文件 <?xml version="1.0" encoding="UTF-8& ...
- Visual C++ Windows 桌面应用程序样例(摘抄)
//================================== //Windows应用程序框架结构(例子) //参考:<Visual C++宝典>陈国建等编著 //======= ...
- 386 Lexicographical Numbers 字典序排数
给定一个整数 n, 返回从 1 到 n 的字典顺序.例如,给定 n =1 3,返回 [1,10,11,12,13,2,3,4,5,6,7,8,9] .请尽可能的优化算法的时间复杂度和空间复杂度. 输入 ...
- ES6十大常用特性
. Default Parameters(默认参数) in ES6 2. Arrow Functions (箭头函数)in ES6 3. Block-Scoped Constructs ...
- python生成动态个性二维码
1 安装工具2 生成普通二维码3 带图片的二维码4 动态 GIF 二维码5 在Python程序中使用 一.安装 首先在python环境下运行, 打开cmd进入python27 进入scripts 然后 ...
- mongo 3.4分片集群系列之三:搭建分片集群--哈希分片 + 安全
这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...
- Anniversary Cake
Anniversary Cake Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15704 Accepted: 5123 ...
- Linux 中ifconfig和ip addr命令查看不到ip解决方法
1.输入查看ip的命令ifconfig或ip addr,查不到ip 2.查看ens33网卡配置,输入 vi /etc/sysconfig/network-scripts/ifcfg-ens33 将ON ...