CodeForces-876B Divisiblity of Differences
2017-11-26 17:47
141 查看
CodeForces-876B Divisiblity of Differences
标签:水题题目链接
/* 题意:给n个数,选k个,要求在k里面任选2个数都能被m整除。 注意n里面可以有相同的数。 思路:对每个数initial[i],保存initial[i]%m在mod[i]。 找出现次数(ans)最多的那个余数,若ans >= k,有解;否组无解。见代码。 */ #include <stdio.h> #include <algorithm> using namespace std; const int maxn = 100005; int initial[maxn], mod[maxn]; int main() { int n, k, m; while(scanf("%d %d %d", &n, &k, &m) != EOF) { for(int i = 0; i < n; i++) { scanf("%d", &initial[i]); mod[i] = initial[i] % m; // } sort(mod, mod + n); //找出现次数(ans)最多的那个余数 int temp = mod[0], total = 0, ans = 0, flag; for(int i = 0; i < n; i++) { if(temp == mod[i]) total++; else { temp = mod[i]; total = 1; //total = 1 } if(total > ans) { ans = total; flag = temp; } } if(ans >= k) //输出 { printf("Yes\n"); int time = 0; for(int i = 0; i < n; i++) { if(initial[i] % m == flag && time < k) //time < k, 选k个数 { printf("%d ", initial[i]); time++; } } printf("\n"); } else printf("No\n"); } return 0; }
相关文章推荐
- [Codeforces 231E] Cactus (环缩点+LCA)
- CodeForces 137A
- Codeforces 549F Yura and Developers
- CodeForces - 955A Feed the cat
- codeforces 231C To Add or Not to Add (脑洞题)
- CodeForces 472 D ,E,F (MST,构造,线性代数)(待补)
- Codeforces 703A. Mishka and Game
- codeforces 330A 330B 329A 分别是7月20DIV2的前三题
- Codeforces 551C GukiZ hates Boxes(二分)
- CodeForces 960 B.Minimize the error
- codeforces 831C Jury Marks
- codeforces-768B Code for 1
- CodeForces 686C Robbers' watch
- CodeForces 154B——Colliders——筛选素数,模拟标记
- Codeforces 552E - Vanya and Brackets【表达式求值】
- Vasya and Chess - CodeForces 493 D 博弈
- Codeforces 424 div1 C. Bamboo Partition 830C 分块优化
- CodeForces 427D Match & Catch 后缀数组
- CodeForces 460B
- CodeForces 276E - Little Girl and Problem on Trees 区间更新..N+1个线段树