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 ...
随机推荐
- 批处理学习:for语句详解【经典】
大纲 一 前言 二 for语句的基本用法 三 for /f (delims.tokens.skip.eol.userbackq.变量延迟) 四 for /r (递归遍历) 五 for /d (遍历目录 ...
- (新手向)基于Bootstrap的简单轮播图的手机实现
个人电脑里存了不少适合手机欣赏的图片,但是放手机里看是件很占据资源的事.鉴于家里有一台电脑经常开着,正好用来做家庭局域网共享,于是笔者就设想通过一种比较简单环保的思路.通过手机访问电脑内的图片. 首先 ...
- mixin设计模式
mixin可以轻松被一个子类或者一组子类继承,目的是函数复用.在js中,我们可以将继承MiXin看作为一种通过扩展收集功能的方式. e.mixin = function(t) { for (var i ...
- 在Nginx服务器中设置多个站点
这里以配置1个站点(1个域名)为例,n 个站点可以相应增加调整, 假设:IP地址: 127.0.0.1域名1 phpmyadmin.zhengwen.cn 放在 /www/phpmyadmin.zhe ...
- ecshop 获取某个商品的 所有订单信息 或者销量
把一下代码放到 lib_main.php 1.统计某个下单商品的人数 function get_goods_ordernum($goods_id){ $sql = "select count ...
- MSA:多重比对序列的格式及其应用
多重比对序列的格式及其应用 这里对多重序列比对格式(Multiple sequence alignment – MSA)进行总结.在做系统演化分析.序列功能分析.基因预测等,都需要涉及到多重序列比 ...
- Python之路【第十二篇续】jQuery案例详解
jQuery 1.jQuery和JS和HTML的关系 首先了HTML是实际展示在用户面前的用户可以直接体验到的,JS是操作HTML的他能改变HTML实际展示给用户的效果! 首先了解JS是一门语言,他是 ...
- [译]git checkout
git checkout git checkout提供3种不同的功能: checking out文件, checking out commits, checking out branch. check ...
- 快速切换IP的批处理!
内容如下: @echo off color 1A Title [SMART专用 IP设置V1.0] cls echo. echo SMART专用 IP设置V1.0 %date%%time% echo. ...
- iOS 滑动性能优化
iOS 滑动性能优化 目录 一. 减少图层的Blend操作 1. UIView的背景色避免使用clearColor 2. 控件贴图避免使用带alpha的图片 3. UIImageView 使用时避免半 ...