HDU5567/BestCoder Round #63 (div.2) A sequence1 水
2015-11-21 22:21
399 查看
[align=left][b]sequence1
[/b][/align]
Given an array a with length n, could you tell me how many pairs (i,j) ( i < j ) for abs(ai−aj) mod b=c.
[align=left]Input[/align]
Several test cases(about 5)
For each cases, first come 3 integers, n,b,c(1≤n≤100,0≤c<b≤109)
Then follows n integers ai(0≤ai≤109)
[align=left]Output[/align]
For each cases, please output an integer in a line as the answer.
[align=left]Sample Input[/align]
3 3 2
1 2 3
3 3 1
1 2 3
[align=left]Sample Output[/align]
1
2
题解:
按照题目要求,枚举任意两个数检查是否符合题意。
值得注意的是一开始所有数先对bb取模这个方法是错误的。
代码
[/b][/align]
Given an array a with length n, could you tell me how many pairs (i,j) ( i < j ) for abs(ai−aj) mod b=c.
[align=left]Input[/align]
Several test cases(about 5)
For each cases, first come 3 integers, n,b,c(1≤n≤100,0≤c<b≤109)
Then follows n integers ai(0≤ai≤109)
[align=left]Output[/align]
For each cases, please output an integer in a line as the answer.
[align=left]Sample Input[/align]
3 3 2
1 2 3
3 3 1
1 2 3
[align=left]Sample Output[/align]
1
2
题解:
按照题目要求,枚举任意两个数检查是否符合题意。
值得注意的是一开始所有数先对bb取模这个方法是错误的。
///1085422276 #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <queue> #include <map> #include <stack> using namespace std; typedef long long ll; #define mem(a) memset(a,0,sizeof(a)) #define pb push_back inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); } while(ch>='0'&&ch<='9'){ x=x*10+ch-'0';ch=getchar(); }return x*f; } //**************************************** const int N=100000+350; #define maxn 100000+5 int main() { int n,b,c,a ; while(scanf("%d%d%d",&n,&b,&c)!=EOF) { for(int i=1;i<=n;i++) { scanf("%d",&a[i]); }int ans=0; for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { if(abs(a[i]-a[j])%b==c) { ans++; } } }cout<<ans<<endl; } return 0; }
代码
相关文章推荐
- hdoj5567sequence1
- UILabel,UITextField,UIButton三大基础控件总结
- BestCoder Round #63 (div.1) A.sequence2
- UItableView
- UESTC 1217 The Battle of Chibi (树状数组 + 离散化 + 动态规划)
- sequence1(暴力)
- hdoj sequence1 5567 (简单暴力)
- HDOJ 5567 sequence1
- HDU 5567 sequence1(暴力)——BestCoder Round #63(div.2)
- IOS_改变UITextField placeHolder颜色、字体
- Serializable中的serialVersionUID到底有啥用
- BestCoder Round #63 (div.2) sequence1
- INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)的解决
- UI基础-UITableView表视图
- 旋转编码器的Arduino使用方法
- poj2299Ultra-QuickSort【逆序数】
- hdu 5567 sequence1(水)
- 判断用户输入是否是数字
- Checklists学习日志之UITableView的全部属性、方法以及代理方法执行顺序
- UILable的lineBreakMode