Sequence1
Given an arrayaWith lengthN, could you tell me how many pairs(i,J) (I < J) fora Bs (ai−a j) mod b=c .
InputSeveral Test Cases (about5)
For each cases, first come 3 integers,N,b,C(1≤n≤,0≤c<b≤9 )
Then followsNIntegersAi(0≤ai≤9)
OutputFor each cases, please output an integer in a line as the answer.
Sample Input3 3 21 2 33 3 11 2 3
Sample Output12
The following:
According to the requirements of the topic, enumerate any two numbers to check if the test instructions is compliant.
It is important to note that the first method of modeling b b is wrong.
///1085422276#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<queue>#include<map>#include<stack>using namespaceStd;typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_backinline ll read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){ if(ch=='-') f=-1; ch=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar (); }returnx*F;}//****************************************Const intn=100000+ -;#defineMAXN 100000+5intMain () {intN,b,c,a[n]; while(SCANF ("%d%d%d", &n,&b,&c)! =EOF) { for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); }intans=0; for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++) { if(ABS (A[i]-a[j])%b==c) {ans++; }}}cout<<ans<<Endl; } return 0;}
Code
Hdu5567/bestcoder Round #63 (Div.2) A Sequence1 Water