zoukankan      html  css  js  c++  java
  • BestCoder Round #61 1001 Numbers

    Problem Description

    There are n numbers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A1,A2....An,your task is to check whether there exists there different positive integers i, j, k (1≤i,j,k≤n1leq i , j , k leq n1i,j,kn) such that Ai−Aj=Ak{A}_{i}-{A}_{j}={A}_{k}AiAj=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)(3leq nleq 100)(3n100). Next line contains n integers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A1,A2....An.(0≤Ai≤1000)(0leq {A}_{i}leq 1000)(0Ai1000)

    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
    ";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
    ";goto n;}
                    }
                }    
            }
            cout<<"NO
    ";
            n: m=0;
            for(i=1;i<=m;i++)
            {
                d[i]=0;
            }
        }
        return 0;
    }
    View Code
    问题描述
    给n个数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A1,A2....An,从中选3个位置不同的数A,B和C,问是否有一种情况满足A-B=C.
    输入描述
    输入有多组数据,不超过1000组.
    每组数据第一行包含一个整数n,随后一行n个整数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A1,A2....An.(3≤n≤1003leq nleq 1003n100,0≤Ai≤10000leq {A}_{i}leq 10000Ai1000)
    输出描述
    对于每组数据如果符合条件输出"YES",否则输出"NO".
    输入样例
    3
    3 1 2
    3
    1 0 2
    4
    1 1 0 2
    输出样例
    YES
    NO
    YES
  • 相关阅读:
    HFun.快速开发平台(一)=》简述
    技术分工论批判(要义)
    后产品意识形态
    鼠标悬停显示图片
    那些特殊边框效果在报表中要怎样实现?
    润乾报表美化设置 -- 样式
    润乾报表如何从 mongodb 中取数
    数据采集录入填报时如何只更新当前修改行
    数据采集填报中自动计算的指标如何做
    数据报表多种序号生成方式
  • 原文地址:https://www.cnblogs.com/dzzy/p/4926346.html
Copyright © 2011-2022 走看看