HDU 5522 Numbers 暴力
Numbers
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5522
Description
Input
There are multiple test cases, no more than 1000 cases.
First line of each case contains a single integer n.(3≤n≤100).
Next line contains n integers A1,A2....An.(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 1 2
3
1 0 2
4
1 1 0 2
Sample Output
YES
NO
YES
HINT
题意
题解:
就n^2暴力,先排序然后从大到小枚举i,把右边的数用一个数组标记其出现过,再枚举左边的数判断其加上Ai是否出现过.
代码
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std; map<int,int> H;
int a[];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
H.clear();
for(int i=;i<=n;i++)
scanf("%d",&a[i]),H[a[i]]++;
sort(a+,a++n);
int flag = ;
for(int i=;i<=n;i++)
{
H[a[i]]--;
for(int j=;j<i;j++)
if(H[a[j]+a[i]])
flag = ;
if(flag)
break;
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}
HDU 5522 Numbers 暴力的更多相关文章
- HDU 5522 Numbers
水题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...
- HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9
/* HDU 6168 - Numbers [ 思维 ] | 2017 ZJUT Multi-University Training 9 题意: .... 分析: 全放入multiset 从小到大,慢 ...
- Hdu oj 5522 Numbers 之解题报告
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABCwAAAL7CAIAAAC5m4NqAAAgAElEQVR4nOy9e7QdVZUvXH+RMcJVdJ
- hdoj 5522 Numbers
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5522 水题:暴力过 #include<stdio.h> #include<strin ...
- hdu 5726 GCD 暴力倍增rmq
GCD/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence ...
- HDU 5510 Bazinga 暴力匹配加剪枝
Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 ...
- hdu 5077 NAND(暴力打表)
题目链接:hdu 5077 NAND 题目大意:Xiaoqiang要写一个编码程序,然后依据x1,x2,x3的值构造出8个字符.如今给定要求生成的8个字符.问 说Xiaoqiang最少要写多少行代码. ...
- Educational Codeforces Round 23 C. Really Big Numbers 暴力
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- hdu 4291(矩阵+暴力求循环节)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4291 思路:首先保留求出循环节,然后就是矩阵求幂了. #include<iostream> ...
随机推荐
- 一天一个Java基础——排序
插入排序 直接插入排序: 当插入第i个数据元素k时,由前i-1个数据元素组成已排序的数据序列,将k与数据序列中各数据元素依次进行比较后,插入到数据序列的适当位置,使得插入后的数据序列仍是排序的. 直接 ...
- 在Android应用中使用Clean架构
自从开始开发安卓应用,我一直感觉我可以做得更好.我看过不少烂代码,其中当然有我写的.安卓系统的复杂性加上烂代码势必酿成灾祸,所以从错误中成长就很重要.我Google了如何更好地开发应用,发现了这个叫做 ...
- MySQL基础之第6章 创建、修改和删除表 .
6.1.创建表 6.1.1.创建表的语法形式 CREATE TABLE 表名 ( 属性名 数据类型 [完整性约束条件],属性名 数据类型 [完整性约束条件],...... 属性名 数据类型); 完整性 ...
- 对Spring IoC容器实现的结构分析
本文的目标:从实现的角度来认识SpringIoC容器. 观察的角度:从外部接口,内部实现,组成部分,执行过程四个方面来认识SpringIoC容器. 本文的风格:首先列出SpringIoC的外部接口及内 ...
- codeforces 678E Another Sith Tournament 概率dp
奉上官方题解 然后直接写的记忆化搜索 #include <cstdio> #include <iostream> #include <ctime> #include ...
- char[]数组与char *指针的区别
char[]数组与char *指针的区别 问题描述 虽然很久之前有看过关于char指针和char数组的区别,但是当时没有系统的整理,到现在频繁遇到,在string,char[], char *中迷失了 ...
- Hadoop2.2.0(yarn)编译部署手册
Created on 2014-3-30URL : http://www.cnblogs.com/zhxfl/p/3633919.html @author: zhxfl Hadoop-2.2编译 ...
- Creating Help Pages for ASP.NET Web API -摘自网络
When you create a web API, it is often useful to create a help page, so that other developers will k ...
- 现代程序设计homework——04
题目: 详见:http://www.cnblogs.com/xinz/p/3341551.html 题目本身确实很难,“很难想到一个比较优雅的算法”,这是一个老师请来专门讲解这道题的大牛的原话.确实, ...
- hibernate hbm2ddl auto 不能创建表的问题
http://fuckgis.blog.sohu.com/148751122.html ________________________________________________________ ...