BestCoder Round #61 1001 Numbers
2015-10-31 21:59
316 查看
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≤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
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}A1,A2....An.(0≤Ai≤1000)(0\leq {A}_{i}\leq 1000)(0≤Ai≤1000)
Output
For each case output "YES" in a single line if you find such i, j, k, otherwise output "NO".
Sample Input
Sample Output
View Code
问题描述
输入描述
输出描述
输入样例
输出样例
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
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}A1,A2....An.(0≤Ai≤1000)(0\leq {A}_{i}\leq 1000)(0≤Ai≤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; }
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≤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
相关文章推荐
- Java基础学习18(类的多态性以及子父类之间的转换机制)
- IBinder接口
- English in October
- Mybatis注解3
- stm32学习笔记——GPIO
- 一些异或运算以及掩码的奇技淫巧
- 【The Expendables】团队博客目录
- ubuntu安装Python环境以及科学计算环境
- springmvc原始入门(帮助理解springmvc流程)
- 主存储器的地址编码问题
- 【系统性能优化】(二)数据库设计
- 乘坐公交
- mybatis使用注解2
- 【Little_things】简单的Client/Server通信小程序(java socket)
- linux驱动platform平台设备总线
- SQL语句的分类
- lvs三种模型
- 研三上学习计划
- 求解最大子数组问题的三种方法
- MAC 下安装MATLAB2014b