http://codeforces.com/contest/370/problem/C

题意:有n个人,m中颜色的手套,开始每个人都是两只相同颜色的手套,经过交换最多可以换出多少个人戴不同颜色的手套。

先按照出现颜色个数排序,然后向后递推交换右手套就可以。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 60000
using namespace std; int n,m;
int c[maxn];
int num[maxn];
struct node
{
int val;
int lco,rco;
int cnt;
bool operator <(const node &a)const
{
return (cnt>a.cnt)||(cnt==a.cnt&&val<a.val);
}
} p[maxn],q[maxn]; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(num,,sizeof(num));
for(int i=; i<n; i++)
{
scanf("%d",&c[i]);
num[c[i]]++;
}
for(int i=; i<n; i++)
{
p[i].val=c[i];
p[i].cnt=num[c[i]];
}
sort(p,p+n);
for(int i=; i<n; i++)
{
p[i].lco=p[i].val;
p[i].rco=p[i].val;
}
int j=p[].cnt;
for(int i=; i<n; i++)
{
if(j>=n) break;
swap(p[i].rco,p[j].rco);
j++;
}
int t1=;
for(int i=; i<n; i++)
{
if(p[i].lco!=p[i].rco) t1++;
}
printf("%d\n",t1);
for(int i=; i<n; i++)
{
printf("%d %d\n",p[i].lco,p[i].rco);
}
}
return ;
}

cf C. Mittens的更多相关文章

  1. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  4. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  5. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  6. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  7. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  8. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  9. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

随机推荐

  1. 搭建完整邮件系统(postfix+dovecot+clamAV+Spamassassin+amavisd-new)

    ============================ 相关软件: 1. 发送邮件 --- postfix 2. 身份认证 --- sasl2 3. 接收邮件 --- dovecot 4. 防病毒邮 ...

  2. 网络编程TCP总结及实践-C语言

    网络变成首先要注意IP和port的转换,如今电脑基本上是主机字节序,存储依照小端方式,而在网络中传输统一使用大端方式,所以网络变成首先要注意字节序的转换. 一个经常使用的ip转换程序的实现: #inc ...

  3. Android 物理按键

    import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view. ...

  4. [Angular 2] ngrx/store

    @ngrx/store builds on the concepts made popular by Redux and supercharges it with the backing of RxJ ...

  5. [RxJS] Creation operators: from, fromArray, fromPromise

    The of() operator essentially converted a list of arguments to an Observable. Since arrays are often ...

  6. A+B问题(java)

    import java.util.Scanner; public class Main { public static void main ( String args[] ) { Scanner in ...

  7. 对static静态成员的理解

    疑惑: 数据成员可以分静态变量.非静态变量两种.  静态成员:静态类中的成员加入static修饰符,即是静态成员.可以直接使用类名+静态成员名访问此静态成员,因为静态成员存在于内存,非静态成员需要实例 ...

  8. nyoj 214

    //nyoj 214 这个题目和字符串的问题类似,都是给出一组数据,寻找最长的单调递增字符 这一题一开始我用dp做,发现超时,看了下时间,n*n的复杂度,换过一种思路 用类似于栈的方式,来存储每次更新 ...

  9. jQuery 基本实现功能模板

    下面是列出了基本功能的实现 <!DOCTYPE html> <html> <head> <script src="http://libs.baidu ...

  10. CSS3 3D转换

    CSS3允许你使用3D转换来对元素进行格式化. 3D转换方法: rotateX() rotateY() 浏览器支持 属性 浏览器支持 transform           IE10和Firefox支 ...