BestCoder Round #61 1001 Numbers
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≤n1\leq i , j , k \leq n1≤i,j,k≤n) such that Ai−Aj=Ak{A}_{i}-{A}_{j}={A}_{k}Ai−Aj=Ak
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}A1,A2....An.(0≤Ai≤1000)(0\leq {A}_{i}\leq 1000)(0≤Ai≤1000)
For each case output "YES" in a single line if you find such i, j, k, otherwise output "NO".
3
3 1 2
3
1 0 2
4
1 1 0 2
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}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≤1003\leq n\leq 1003≤n≤100,0≤Ai≤10000\leq {A}_{i}\leq 10000≤Ai≤1000)
对于每组数据如果符合条件输出"YES",否则输出"NO".
3
3 1 2
3
1 0 2
4
1 1 0 2
YES
NO
YES
BestCoder Round #61 1001 Numbers的更多相关文章
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...
- 暴力 BestCoder Round #41 1001 ZCC loves straight flush
题目传送门 /* m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 ╰· */ #include <cstdio> #include < ...
- 暴力 BestCoder Round #46 1001 YJC tricks time
题目传送门 /* 暴力:模拟枚举每一个时间的度数 详细解释:http://blog.csdn.net/enjoying_science/article/details/46759085 期末考结束第一 ...
- 字符串处理 BestCoder Round #43 1001 pog loves szh I
题目传送门 /* 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 */ #include <cstdio> #incl ...
- BestCoder Round #75 1001 - King's Cake
Problem Description It is the king's birthday before the military parade . The ministers prepared a ...
- BestCoder Round #92 1001 Skip the Class —— 字典树 or map容器
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1001 题解: 1.trie树 关 ...
- BestCoder Round #87 1001
GCD is Funny Accepts: 524 Submissions: 1147 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 655 ...
- BestCoder Round #60 1001
Problem Description You are given a sequence of NNN integers. You should choose some numbers(at leas ...
- BestCoder Round #61 (div.2)
Numbers Accepts: 571 Submissions: 1212 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/26 ...
随机推荐
- Distinct
SELECT 指令让我们能够读取表格中一个或数个栏位的所有资料.这将把所有的资料都抓出,无论资料值有无重复.在资料处理中,我们会经常碰到需要找出表格内的不同资料值的情况.换句话说,我们需要知道这个表格 ...
- Java适配器设计模式
适配器设计模式,一个接口首先被一个抽象类先实现(此抽象类通常称为适配器类),并在此抽象类中实现若干方法(但是这个抽象类中的方法体是空的),则以后的子类直接继承此抽象类,就可以有选择地覆写所需要的方法. ...
- JavaWeb学习笔记——访问静态HTML网页
基础知识: 1.一个标准 的WEB应用,在根目录下必须有一个WEB-INF文件夹,文件夹下必须有一个WEB.xml文件. 2.classes文件夹用来存放编译的class文件. 3.lib文件夹用来存 ...
- *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory
报错提示: *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndex ...
- aufomaper Queryable Extensions ProjectTo
When using an ORM such as NHibernate or Entity Framework with AutoMapper's standard Mapper.Map funct ...
- 使用phpize增加php模块
一,phpize的好处 什么时候我们要用phpize呢?我们在安装php时: ./configure --prefix=/apps/product/php --with-config-file-pat ...
- "Java 反序列化"过程远程命令执行漏洞
一.漏洞描述 国外 FoxGlove 安全研究团队于2015年11月06日在其博客上公开了一篇关于常见 Java 应用如何利用反序列化操作进行远程命令执行的文章.原博文所提到的 Java 应用都使 ...
- composer错误收集
1. Problem 1 - The requested package ** is satisfiable by ** but these conflict with your requiremen ...
- 在VS2013中强制IIS Express应用程序池使用经典模式
直接在文件夹地址栏输入 %userprofile%\documents\iisexpress\config\applicationhost.config 会打开上边的配置文件 将 <siteDe ...
- Thinkphp 连接查询的使用
方法一:使用table()方法 $tables = 'b_order ordert, b_busbid busbid'; $map['busbid.buscompanyid'] = 1; $map[' ...