Codeforces 376C. Socks】的更多相关文章

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 prep…
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…
题目: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…
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number a doesn't contain any leading zeroes and contains…
题意:有n只袜子,k种颜色,在m天中,问最少修改几只袜子的颜色,可以使每天穿的袜子左右两只都同颜色. 析:很明显,每个连通块都必须是同一种颜色,然后再统计最多颜色的就好了,即可以用并查集也可以用DFS. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include…
Socks Problem 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…
地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andryusha is an orderly boy and likes to keep things in their plac…
题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o…
http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问要让每天的袜子是相同颜色的,要重新染色的袜子数最少是多少. 思路:并查集合并,将同一天的袜子合并起来,然后就形成了cnt个集合,每个集合都是独立的,因此排序,找出每个集合里面袜子颜色相同的最多的是哪个颜色,然后把其他不属于这个颜色的都染成这个颜色,那么这样重新染色的袜子数是最少的.然后每个集合的答案…