Problem Description

There are n numbers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​,your task is to check whether there exists there different positive integers i, j, k (1≤i,j,k≤n1\leq i , j , k \leq n1≤i,j,k≤n) such that Ai−Aj=Ak{A}_{i}-{A}_{j}={A}_{k}A​i​​−A​j​​=A​k​​

Input

There are multiple test cases, no more than 1000 cases. First line of each case contains a single integer n.(3≤n≤100)(3\leq n\leq 100)(3≤n≤100). Next line contains n integers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​.(0≤Ai≤1000)(0\leq {A}_{i}\leq 1000)(0≤A​i​​≤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 大水题,快排一下两个循环搞一下就好 23333 用goto嘲讽了,我的锅
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int donser(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
freopen("in.txt","r",stdin);
int i,j,k,m,d[];
while(~scanf("%d",&m))
{
for(i=;i<=m;i++)
{
scanf("%d",&d[i]);
}
qsort(d+,m,sizeof(int),donser);
if(m<){cout<<"NO\n";goto n;}
for(i=;i<=m-;i++)
{
for(k=i+;k<=m-;k++)
{
for(j=k+;j<=m;j++)
{
if(d[i]+d[k]==d[j]){cout<<"YES\n";goto n;}
}
}
}
cout<<"NO\n";
n: m=;
for(i=;i<=m;i++)
{
d[i]=;
}
}
return ;
}
问题描述
给n个数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​,从中选3个位置不同的数A,B和C,问是否有一种情况满足A-B=C.
输入描述
输入有多组数据,不超过1000组.
每组数据第一行包含一个整数n,随后一行n个整数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​.(3≤n≤1003\leq n\leq 1003≤n≤100,0≤Ai≤10000\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

BestCoder Round #61 1001 Numbers的更多相关文章

  1. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  2. 暴力 BestCoder Round #41 1001 ZCC loves straight flush

    题目传送门 /* m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 ╰· */ #include <cstdio> #include < ...

  3. 暴力 BestCoder Round #46 1001 YJC tricks time

    题目传送门 /* 暴力:模拟枚举每一个时间的度数 详细解释:http://blog.csdn.net/enjoying_science/article/details/46759085 期末考结束第一 ...

  4. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 /* 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 */ #include <cstdio> #incl ...

  5. BestCoder Round #75 1001 - King's Cake

    Problem Description It is the king's birthday before the military parade . The ministers prepared a ...

  6. BestCoder Round #92 1001 Skip the Class —— 字典树 or map容器

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1001 题解: 1.trie树 关 ...

  7. BestCoder Round #87 1001

    GCD is Funny Accepts: 524 Submissions: 1147 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 655 ...

  8. BestCoder Round #60 1001

    Problem Description You are given a sequence of NNN integers. You should choose some numbers(at leas ...

  9. BestCoder Round #61 (div.2)

    Numbers Accepts: 571 Submissions: 1212 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/26 ...

随机推荐

  1. linux安装pip

    1.先说一下什么是pippip 是"A tool for installing and managing Python packages.",也就是说pip是python的软件安装 ...

  2. bootstrap的学习-基础样式和排版一

    一.列表去除样式和横排排列 classs="list-unstyled","list-inline" 二.[表格].table 类指定基本样式,.table-s ...

  3. 视频直播APP开发分析

    视频直播APP开发到目前为止都还是热门的一个行业,而且发展到现在直播的种类非常多,很多行业都打入了直播行业,再也不是单纯的人物直播这么单一了.视频直播APP开发行业就像是吃螃蟹,来的早的人不懂如何吃, ...

  4. easyUI datagrid view扩展

    //扩展easyuidatagrid无数据时显示界面 var emptyView = $.extend({}, $.fn.datagrid.defaults.view, { onAfterRender ...

  5. easyUI layout 中使用tabs+iframe解决请求两次方法

    demo中的事例在加载tab页面时是 function createFrame(url) { var s = '<iframe name="iframepanel" scro ...

  6. UITextField限制输入文字

    一.viewDidLoad时监听通知 NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addO ...

  7. 在64位系统上不能安装Matlab notebook的解决方案

    在64位系统上不能安装Matlab notebook的解决方案 过程分解 第一步:安装好matlab(附:Matalab R2015a界面) 第二步:在matlab中执行命令 >>note ...

  8. JS获取checkbox的个数

    本文算是转载自网络,当时用了他的函数,现在想总结一下,但忘了原文地址了 ================================================================ ...

  9. Page传回页面的值问题

  10. 本地wampserver如何配置伪静态

    本地wamp实现虚拟主机后,我把自己的站放进去就出现了500错误看日志看到.htaccess: Invalid command ‘RewriteEngine’, perhaps misspelled ...