C. Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output   Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have pr…
题目:http://codeforces.com/contest/731/problem/C 思路:并查集处理出哪几堆袜子是同一颜色的,对于每堆袜子求出出现最多颜色的次数,用这堆袜子的数目减去该值即为这堆袜子需要修改的颜色数,用同样的方法处理每堆求和即可. #include<bits/stdc++.h> using namespace std; ],c[]; map<int,map<int,int> > mp; int getf(int x){ if(f[x] == x…
http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问要让每天的袜子是相同颜色的,要重新染色的袜子数最少是多少. 思路:并查集合并,将同一天的袜子合并起来,然后就形成了cnt个集合,每个集合都是独立的,因此排序,找出每个集合里面袜子颜色相同的最多的是哪个颜色,然后把其他不属于这个颜色的都染成这个颜色,那么这样重新染色的袜子数是最少的.然后每个集合的答案…
题目链接:http://codeforces.com/contest/731/problem/C 题意:有n只袜子(1~n),k种颜色(1~k),在m天中,左脚穿下标为l,右脚穿下标为r的袜子,问最少修改几只袜子的颜色,可以使每天穿的袜子左右两只都同颜色. 好恶心的袜子,一会儿看成改袜子的颜色,一会儿看成改l,r的颜色,一会下标看混......不过,菜是原罪=_= 思路:先建图,在每个连通分支中,把所有袜子的颜色都改成出现颜色次数最多的那个颜色,即该分支节点个数 - 最多出现次数 #includ…
C. Socks time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have…
http://codeforces.com/problemset/problem/731/C 并查集+贪心 将要求颜色相同的袜子序号放入一个集合中 贪心:然后统计这个集合中出现次数最多但颜色 可以得到这个集合要repain的次数 代码有难度 统计集合数 int tot;//总的集合数 for (int i = 1; i <= n; i++) if(par[i] == i) { rec[tot++] = i;//记录根节点 } //统计每个集合红颜色的个数 map<int, int> cl…
A - Infinite Sequence  CodeForces - 622A 题目大意:给你一个这样的数列1,1,2,1,2,3,1,2,3,4,1,2,3,4,5....就是从1~n排列(n++).最后问你第n个位置是什么数字. 思路:如果你花点时间列数列的话会发现,1~n的最后一位对应的位置是1~n的和,那我们就大胆使用二分进行搜索这位数. #include<iostream> #include<algorithm> #include<cstdio> #incl…
B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output     Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some st…
Description Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her leave she real…
题意:有n只袜子,k种颜色,在m天中,问最少修改几只袜子的颜色,可以使每天穿的袜子左右两只都同颜色. 析:很明显,每个连通块都必须是同一种颜色,然后再统计最多颜色的就好了,即可以用并查集也可以用DFS. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include…