BestCoder Round #61 1001 Numbers

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[2000];
    while(~scanf("%d",&m))
    {
        for(i=1;i<=m;i++)
        {
            scanf("%d",&d[i]);
        }
        qsort(d+1,m,sizeof(int),donser);
        if(m<3){cout<<"NO\n";goto n;}
        for(i=1;i<=m-2;i++)
        {
            for(k=i+1;k<=m-1;k++)
            {
                for(j=k+1;j<=m;j++)
                {
                    if(d[i]+d[k]==d[j]){cout<<"YES\n";goto n;}
                }
            }
        }
        cout<<"NO\n";
        n: m=0;
        for(i=1;i<=m;i++)
        {
            d[i]=0;
        }
    }
    return 0;
}

问题描述

给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
时间: 2024-07-29 06:59:51

BestCoder Round #61 1001 Numbers的相关文章

BestCoder Round #29 1001 GTY&#39;s math problem

GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description GTY is a GodBull who will get an Au in NOI . To have more time to learn alg

BestCoder Round #1 1001 &amp;&amp; 1002 hdu 4857 4858

hdu 4857 逃生 第一题是拓扑排序,不是按照字典序最小输出,而是要使较小的数排在最前面..赛后弄了好久,才比较明白,我一直以为 反向建图,i从1到n,开始深搜dfs( i ),对i点的边,由小到大继续搜一下,同时标记搜过的数,搜过之后就不再搜,搜到底之后ans[cnt++] = u;这样顺序输出就是答案,后来经过超哥指点,才明白深搜贪心是错的.只有 反向建图,用优先队列把较大的数尽量排在前面,然后反序输出才是正解.. 1 #include<iostream> 2 #include<

BestCoder Round #2 1001 TIANKENG’s restaurant

不得不说,bastcoder是个hack游戏啊!!! 题意:求最少要多少张椅子才能让所有来的客人有地方坐!! 就是一个区间的处理吧!!!和HDU  1556 我待水似流年,流年待我似水神似!!!! 求的是重叠的区间最大,我们只要标记每个区间会有多少人就可以了!!! 然后在从0到1440分统计就OK了!! AC代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<map> #inc

BestCoder Round #2 1001 (简单处理)

题目链接 题意:给N条信息,每个信息代表有x个人从开始的时间 到 结束的时间在餐厅就餐, 问最少需要多少座位才能满足需要. 分析:由于时间只有24*60 所以把每个时间点放到 数组a中,并标记开始的时间+x, 结束的时间 -x.最后累加比较. 如果时间点太多的时候可以把时间点放到结构体里,排序,然后依次枚举结构体. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <

HDU BestCoder Round #1 1001 逃生 【拓扑排序】

逃生 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能排成一行. 现在有n个人,从1标号到n.同时有一些奇怪的约束条件,每个都形如:a必须在b之前. 同时,社会是不平等的

HDU 5280 BestCoder Round #47 1001:Senior&#39;s Array

Senior's Array Accepts: 199 Submissions: 944 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 某天学姐姐得到了一个数组A,在这个数组的所有非空区间中,她找出了一个区间和最大的,并把这个区间和定义为这个数组的美丽值. 但是她觉得这个数组不够美,于是决定修理一下这个数组. 学姐姐将会进行一次操作,把原数组中的某个数修改为P(必须修改)

BestCoder Round #3 1001 &amp;&amp; HDU 4907 Task schedule (预处理)

题目链接:HDU 4907 Task schedule 中文题. 思路:将工作表存在vis的组数中.预处理一遍.具体看代码 AC代码: #include<stdio.h> #include<string.h> bool vis[200100]; int tak[200100]; int main() { int j,i,ti; int n,m,t,num; while(scanf("%d",&t)!=EOF) { while(t--) { memset(

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

题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 using namespace std; 9 10 typedef long long ll; 11 const int MAXN = 1

暴力 BestCoder Round #41 1001 ZCC loves straight flush

题目传送门 1 /* 2 m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 3 ╰· 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 using namespace std; 11 12 const int MAXN = 1