HDU 5522 Numbers(暴力)——BestCoder Round #61(div.2)
2015-10-31 23:04
375 查看
Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/262144 K (Java/Others)Problem Description
There are n numbers A1,A2....An
,your task is to check whether there exists there different positive integers i, j, k (1≤i,j,k≤n)
such that Ai−Aj=Ak
Input
There are multiple test cases, no more than 1000 cases.
First line of each case contains a single integer n.(3≤n≤100).
Next line contains n integers A1,A2....An. (0≤Ai≤1000)
Output
For each case output "YES" in a single line if you find such i, j, k, otherwise output "NO".
Sample Input
3 3 1 2 3 1 0 2 4 1 1 0 2
Sample Output
YES NO YES
Source
BestCoder Round #61 (div.2)
/************************************************************************/
附上该题对应的中文题
Numbers
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/262144 K (Java/Others)
问题描述
给n个数{A}_{1},{A}_{2}....{A}_{n}A1,A2....An,从中选3个位置不同的数A,B和C,问是否有一种情况满足A-B=C.
输入描述
输入有多组数据,不超过1000组. 每组数据第一行包含一个整数n,随后一行n个整数{A}_{1},{A}_{2}....{A}_{n}A1,A2....An.(3\leq n\leq 1003≤n≤100,0\leq {A}_{i}\leq 10000≤Ai≤1000)
输出描述
对于每组数据如果符合条件输出"YES",否则输出"NO".
输入样例
3 3 1 2 3 1 0 2 4 1 1 0 2
输出样例
YES NO YES
/****************************************************/
出题人的解题思路:
Numbers
先排序然后从大到小枚举i,把右边的数用一个数组标记其出现过,再枚举左边的数判断其加上Ai是否出现过.其实这道题的n比较小,完全可以暴力妥妥过,复杂度O(n^3)也不过是百万,只要中间判断一下i,j,k是不是相同就可以了
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 using namespace std; const int N = 105; const int M = 100005; const int inf = 100000000; const int mod = 2009; int s ; int main() { int n,i,j,k; bool flag; while(~scanf("%d",&n)) { flag=false; for(i=0;i<n;i++) scanf("%d",&s[i]); for(i=0;i<n&&!flag;i++) for(j=0;j<n&&!flag;j++) for(k=0;k<n&&!flag;k++) if(i==j||i==k||j==k) continue; else if(s[i]-s[j]==s[k]) { puts("YES"); flag=true; } if(!flag) puts("NO"); } return 0; }菜鸟成长记
相关文章推荐
- tyvj1084数字三角形4
- 使用 openssl 命令行构建 CA \b及证书 (二)
- SSH框架搭建图文详解
- 机器学习之回归分析——Logistic regression
- BestCoder Round #61 (div.2) 1001
- Oracle实战——数据查询与更新
- Systems
- Java 三大框架SSH,自学先学哪个?
- MOOC PTA 08-图8 How Long Does It Take
- tyvj1079数字三角形3
- 一组数据中只有一个数字出现一次,其他数成对出现,找出这个数
- Memcached入门(一)
- cvStereoRectify 报错
- NSFileManager文件操作
- Servlet 生命周期、工作原理
- URL、URI和URN三者之间的区别
- 使用 openssl 命令行构建 CA \b及证书(一)
- tyvj1044数字三角形
- LightOJ - 1060 nth Permutation(计数)
- 英语学习重要性