CodeForces 370C
2024-09-05 07:11:01
这道题其实是挺简单的。首先很容易发现最多人用的颜色的人数如果大于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 ;
}
最新文章
- 三层架构的OPP实现的演示例子
- 脚本tips
- Solve error: Cannot open include file: &#39;X11/Xlocale.h&#39;: No such file or directory
- C语言之移位操作
- java web项目 。classpath 文件解析
- SGU 103.Traffic Lights(最短路)
- HTML5之选择上传图片文件
- C#操作AD的例子
- 打印man手册为pdf文件
- 常用的linux系统监控命令整理
- C#中的协变(Covariance)和逆变(Contravariance)
- Autofac学习之三种生命周期:InstancePerLifetimeScope、SingleInstance、InstancePerDependency
- 可空类型 Nullable<;T>;
- pycharm 安装与基本设置
- post插件
- Go语言 并发编程
- 信息检索中的TF/IDF概念与算法的解释
- js中创建数组,并往数组里添加元素
- Visual studio中编译和使用libpng和zlib
- Python Algorithms – chapter2 基础知识