HDU 5522 Numbers
来源:互联网 发布:电锯惊魂影评知乎 编辑:程序博客网 时间:2024/05/22 01:31
Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/262144 K (Java/Others)Total Submission(s): 924 Accepted Submission(s): 517
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 integersA1,A2....An .(0≤Ai≤1000)
First line of each case contains a single integer n.
Next line contains n integers
Output
For each case output "YES" in a single line if you find such i, j, k, otherwise output "NO".
Sample Input
33 1 231 0 241 1 0 2
Sample Output
YESNOYES
Source
BestCoder Round #61 (div.2)
BestCoder上的一道水题,碰巧看见了。
不多说,没优化,但能过。O(n^3) 暴力
#include <stdio.h>#include <algorithm>using namespace std;const int MAXN=105;int a[MAXN];int main(){ int n; while(scanf("%d",&n)>0) { for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int isOk=0; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) for(int k=j+1;k<n;k++) if((a[i]+a[j])==a[k]) { isOk=1; break; } if(isOk) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- HDU 5522 Numbers
- HDU 5522 Numbers
- hdu 5522 Numbers(水)
- (枚举)HDU 5522 Numbers
- Numbers HDU
- HDU 5522 Numbers (暴力枚举)
- HDU 5522 Numbers(枚举 + 二分查找)
- HDU 3117 Fibonacci Numbers
- hdu 3117 Fibonacci Numbers
- HDU 1058 Humble Numbers
- hdu 1390 Binary Numbers
- hdu 1058 Humble Numbers
- hdu 1128 Self Numbers
- hdu 3117 Fibonacci Numbers
- hdu 1058 Humble Numbers
- HDU 1128 self numbers
- HDU 1390 Binary Numbers
- HDU Humble Numbers
- 今天算是开博的第一天,希望能记录我菜鸟的成长之路吧
- LINUX几个常用到的命令
- leetcode 20 Valid Parentheses
- SQL与NoSQL,谁更适合大数据?主流的关系型数据库?什么是JSON?
- 5.Foundaton Kit介绍 部分一
- HDU 5522 Numbers
- leetcode32 Longest Valid Parentheses
- 解决oracle 表被锁住问题
- leetcode150 Evaluate Reverse Polish Notation
- IOS插件管理工具—Alcatraz
- linux centos 安装xampp
- SQL语句教程
- History对象
- 微服务与SOA的实践应用对比