您的位置:首页 > 其它

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}A​1​​,A​2​​....A​n​​,从中选3个位置不同的数A,B和C,问是否有一种情况满足A-B=C.


输入描述
输入有多组数据,不超过1000组.
每组数据第一行包含一个整数n,随后一行n个整数{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​.(3\leq n\leq 1003≤n≤100,0\leq {A}_{i}\leq 10000≤A​i​​≤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;
}
菜鸟成长记
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: