HDOJ 5567 sequence1 (暴力)
2015-11-23 20:50
621 查看
sequence1
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 219 Accepted Submission(s): 168
[align=left]Problem Description[/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
题意:查看|(a[i]-a[j])|%b==c的组合有多少,i<j
思路:数据只有1k,直接暴力
ac代码:
#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #define MAXN 10000001 #define fab(a) (a)>0?(a):(-a) #define INF 0xfffffff #define LL long long using namespace std; LL a[MAXN]; int main() { LL n,b,c; int i,j; while(~scanf("%lld%lld%lld",&n,&b,&c)) { for(i=0;i<n;i++) scanf("%lld",&a[i]); LL ans=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { LL k=a[i]-a[j]; if(k<0) k=-k; if(k%b==c) ans++; } } printf("%lld\n",ans); } return 0; }
相关文章推荐
- UIAlertController与 UIAlertView
- GUI对话框
- iOS开发--UITableViewCell侧滑多个按钮(系统仅支持iOS8以上)
- Handler Looper MessageQueue的应用
- UITableviewcell的删除操作
- iOS 中的线程(1)---①performSelectorInBackground②NSThread③NSOperation 和 NSOperationQueue 的组合
- MySQL query / clause execution order
- ueditor过滤
- IOS之UI -- UITableView -- 1 -- 相关初识
- [android] 优化UI卡顿现象
- xmanager - xstart - The X11 forwarding request was rejected
- Kibana User Guide [4.2] » Using Kibana in a Production Environment
- [转]Bluetooth LE Credit-Based Flow Control for L2CAP Connection-Oriented Channels
- easyui 合并
- suibi
- [TwistedFate]UITableView表视图编辑,移动
- codeforces 597C Subsequences
- Github gui使用
- UIAlertView
- UINavigationController总结