题目链接:http://codeforces.com/contest/876/problem/B 题意: 给你n个数a[i],让你找出一个大小为k的集合,使得集合中的数两两之差为m的倍数. 若有多解,输出任意一个集合即可. 题解: 若一个集合中的数,两两之差为m的倍数,则他们 mod m 的值均相等. 所以O(N)扫一遍,对于每个数a:vector v[a%m].push_back(a) 一旦有一个集合大小为k,则输出. AC Code: #include <iostream> #includ…
题意:给定n个数,从中选取k个数,使得任意两个数之差能被m整除,若能选出k个数,则输出,否则输出“No”. 分析: 1.若k个数之差都能被m整除,那么他们两两之间相差的是m的倍数,即他们对m取余的余数是相同的. 2.记录n个数对m取余的余数,计算出数量最多的余数ma. 3.ma>=k,才能选出,并输出即可. #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #in…
B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output You are given a multiset of n integers. You should select exactly k of them in a such way that the difference b…
B. Divisiblity of Differences You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the origi…
B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output You are given a multiset of n integers. You should select exactly k of them in a such way that the difference b…
B. Divisiblity of Differencestime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a multiset of n integers. You should select exactly k of them in a such way that the difference between an…
B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output You are given a multiset of n integers. You should select exactly k of them in a such way that the difference b…
http://codeforces.com/contest/876/problem/B 题意: 给出n个数,要求从里面选出k个数使得这k个数中任意两个的差能够被m整除,若不能则输出no. 思路: 差能够被m整除,其实就是对m取余的余数相同.那么就统计n个数的余数丢到一个map里面,最后判断是否有某个数的数量大于等于k. 代码: #include <stdio.h> #include <map> #include <vector> using namespace std;…
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是2.但由于n不一定是质数,我们还需要再加k条边.然后对于\(i \in [1,k]\),我们加边(i,i+n/2).当\(k\leq \frac{n}{2}\)的时候,只会把一些点的度数由2变成3,否则会出现重边问题.假设新图的边数为m,那\(m \in [n,n+\frac{n}{2}]\),如果…
题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s    a xor b = x   a, b > 0. 让你求符合条件的a b有多少对 思路: a + b = s , a ^ b = x   ==>   s - x = (a & b) * 2 #include <bits/stdc++.h> using namespace std; typedef long long LL;…