首页 > 其他分享 >Divisiblity of Difference

Divisiblity of Difference

时间:2024-08-21 16:40:29浏览次数:8  
标签:cout int bmod Divisiblity 余数 Difference

题目传送门

思路

首先得知道个性质,即若 $a \bmod b = c \bmod b$,那么 $(a-c) \bmod b =0$,因为余数在 $(a-c)$ 中被减掉了。

于是我们可以把所有余数相同的 $a_i$ 丢进一个 vector 里,之后再看余数相同的 $a_i$ 的数量有没有 $\ge k$,有的话就输出前 $k$ 个数,没有就输出 No。

代码

#include<bits/stdc++.h>
using namespace std;
int n,k,m,ans,id;
vector<int> y[100005];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(),cout.tie();
	cin>>n>>k>>m;
	for(int x,i=1;i<=n;i++)
		cin>>x,y[x%m].push_back(x);
	for(int i=0;i<m;i++){
		if(y[i].size()>=k){
			cout<<"Yes"<<endl;
			for(int j=0;j<k;j++)
				cout<<y[i][j]<<" ";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

标签:cout,int,bmod,Divisiblity,余数,Difference
From: https://www.cnblogs.com/WuMin4/p/18371951

相关文章

  • C++ STL adjacent_difference 用法
    一:功能    计算相邻两个元素的差(默认),也可以使用其他自定义运算函数,比如计算相邻两个元素的和。二:用法#include<iostream>#include<vector>#include<numeric>intmain(){std::vector<int>data{2,3,5,7,11,13};//前两个参数指定输入的范围,第......
  • Visible and Clear: Finding Tiny Objects in Difference Map
    VisibleandClear:FindingTinyObjectsinDifferenceMap论文链接:https://arxiv.org/abs/2405.11276项目链接:https://github.com/Hiyuur/SR-TOD(ECCV2024)Abstract微小目标检测是目标检测领域的关键问题之一。大多数通用检测器的性能在微小目标检测任务中显著下降......
  • STL--求交集,并集,差集(set_intersection,set_union,set_difference)
    set_intersection(重要)求两个有序的序列的交集.函数声明如下:template<classInputIterator1,classInputIterator2,classOutputIterator>OutputIteratorset_intersection(InputIterator1_First1,//容器1开头InputIterator1_Last1,//容器2......
  • What is the difference between OpenAI and ChatOpenAI in LangChain?
    题意:在LangChain中,OpenAI 和 ChatOpenAI 的主要区别是什么?问题背景:IreadtheLangChainQuickstart.Thereisademoinside:        里面有一个演示:fromlangchain.llmsimportOpenAIfromlangchain.chat_modelsimportChatOpenAIllm=OpenAI()chat......
  • [AGC066A] Adjacent Difference
    [AGC066A]AdjacentDifference考虑我们生成的矩阵中的数都是\(d\)的倍数我们显然只需要保证\(a'_{i,j}=xd\)中的\(x\)互不相同即可我们钦定根据\(i+j\)的奇偶性来设置\(x\)为\(0\)或\(1\),\(a_{i,j}\equivxd\pmod{2d}\)我们尝试只对\(x=0\)时分析它此时的代......
  • [LeetCode] 2903. Find Indices With Index and Value Difference I
    Youaregivena0-indexedintegerarraynumshavinglengthn,anintegerindexDifference,andanintegervalueDifference.Yourtaskistofindtwoindicesiandj,bothintherange[0,n-1],thatsatisfythefollowingconditions:abs(i-j)>=index......
  • 题解【[ABC147F] Sum Difference】
    题目链接下为口胡题解:入手方向推导:直接考虑题目所给式子显然困难:\[w(S)=\sum_{i\inS}A_i-\sum_{i\notinS}A_i\]因为两个式子虽然相关但是都在变化,不妨转化为:\[w(S)=2\times\sum_{i\inS}A_i-\sum_{i=1}^nA_i\]这样只用求出有多少个不同的\(\sum_{i\inS}A_i\)。由于......
  • POI2011ROZ-Difference
    POI#Year2011#枚举#贪心枚举最后差最大的两个字符\(a,b\),将原串中\(a\rightarrow1,b\rightarrow-1\),其他标\(0\)原来的问题转化为强制包含\(1,-1\)的最大字段和问题,维护每个位置前最近的\(-1\),贪心取最大的//Author:xiaruizeconstintMOD=1000000007;const......
  • 52 Things: Number 40: What is normally considered the difference between SPA and
    52Things:Number40:WhatisnormallyconsideredthedifferencebetweenSPAandDPA?52件事:第40件:通常认为SPA和DPA之间的区别是什么? Thisisthelatestinaseriesofblogpoststoaddressthelistof '52ThingsEveryPhDStudentShouldKnowToDoCryptogr......
  • 52 Things: Number 38: What is the difference between a covert channel and a side
    52Things:Number38:Whatisthedifferencebetweenacovertchannelandaside-channel?52件事:第38件:隐蔽通道和侧通道之间的区别是什么? Thisisthelatestinaseriesofblogpoststoaddressthelistof'52ThingsEveryPhDStudentShouldKnowToDoCrypt......