BestCoder Round #61 (div.2)
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
题解:刚开始用vector写的,发现原来没有count。。。就改成了;
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=;
int m[MAXN];
int cnt[MAXN];
set<int>st;
int main(){
int n;
while(~scanf("%d",&n)){
st.clear();
memset(cnt,,sizeof(cnt));
for(int i=;i<n;i++){
scanf("%d",m+i);
st.insert(m[i]);
cnt[m[i]]++;
}
int su,flot=;
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
su=m[i]+m[j];
if(su==m[i]||su==m[j]){
if(cnt[su]==)continue;
}
if(m[i]==m[j]&&m[i]==su){
if(cnt[su]==)continue;
}
if(st.count(su)){
flot=;
break;
}
}
if(flot)break;
}
if(flot)puts("YES");
else puts("NO");
}
return ;
}
Game
XY is playing a game:there are N pillar in a row,which numbered from 1 to n.Each pillar has a jewel.Now XY is standing on the S-th pillar and the exit is in the T-th pillar.XY can leave from the exit only after they get all the jewels.Each time XY can move to adjacent pillar,or he can jump to boundary ( the first pillar or the N-th pillar) by using his superpower.However,he needs to follow a rule:if he left the pillar,he no can not get here anymore.In order to save his power,XY wants to use the minimum number of superpower to pass the game.
There are multiple test cases, no more than 1000 cases. For each case,the line contains three integers:N,S and T.(1≤N≤10000,1≤S,T≤N)(1\leq N\leq10000,1\leq S,T\leq N )(1≤N≤10000,1≤S,T≤N)
The output of each case will be a single integer on a line: the minimum number of using superpower or output -1 if he can't leave.
4 1 4
4 1 3
0
1
题解:各种判断。。。
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
const int INF=0x3f3f3f3f;
int FABS(int x){
return x>?x:-x;
}
int main(){
int N,S,T;
while(~scanf("%d%d%d",&N,&S,&T)){
if(N==)puts("");
else if(S==T)puts("-1");
else if(S==||S==N){
if(T==||T==N)puts("");
else puts("");
}
else if(T==||T==N){
if(FABS(T-S)==)puts("");
else
puts("");
}
else{
if(FABS(T-S)==)puts("");
else
puts("");
}
}
return ;
}
BestCoder Round #61 (div.2)的更多相关文章
- BestCoder Round #61 (div.2) C.Subtrees dfs
Subtrees 问题描述 一棵有N个节点的完全二叉树,问有多少种子树所包含的节点数量不同. 输入描述 输入有多组数据,不超过1000组. 每组数据输入一行包含一个整数N.(1\leq N\leq ...
- BestCoder Round #61 (div.2) B.Game 细节题
Game 问题描述 XY在玩一个游戏:有N根柱子排成一排,编号为1到N,每个柱子上面有一块宝石,现在XY站在第S根柱子上,出口在第T跟柱子上,XY需要拿到所有宝石后从出口离开.每次XY可以走到相邻 ...
- HDU5526/BestCoder Round #61 (div.1)1004 Lie 背包DP
Lie 问题描述 一个年级总共有N个学生,每个人属于唯一一个班级.现在他们站在一排,同班同学并不一定会站在一起,但每个人都会说一句话:“站在我左边的有Ai个同班同学,右边有Bi个同班同学”.然而并 ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- BestCoder Round #68 (div.2) tree(hdu 5606)
tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- BestCoder Round #11 (Div. 2) 题解
HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu5635 BestCoder Round #74 (div.2)
LCP Array Accepts: 131 Submissions: 1352 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- hdu5634 BestCoder Round #73 (div.1)
Rikka with Phi Accepts: 5 Submissions: 66 Time Limit: 16000/8000 MS (Java/Others) Memory Limit: ...
随机推荐
- 将单链表的每K个节点之间逆序
[说明]: 本文是左程云老师所著的<程序员面试代码指南>第二章中“将单链表的每K个节点之间逆序”这一题目的C++复现. 本文只包含问题描述.C++代码的实现以及简单的思路,不包含解析说明, ...
- IIS发布网站后局域网其他用户不能访问问题(转)
如果本机能正常访问,而局域网其他用户不能访问,那么判断的结果很可能是防火墙问题. 解决方法: 既然问题出在Windows7或Windows Server 2008 R2的防火墙上,那么我们可以有以下两 ...
- oracle中区分audit_file_dest, background_dump_dest, core_dump_dest, user_dump_dest
一般在$ORACLE_HOME\admin\{SID}目录下: audit_file_dest = /u01/app/oracle/admin/{SID}/adump ...
- hdu 4033 Regular Polygon 计算几何 二分+余弦定理
题目链接 给一个n个顶点的正多边形, 给出多边形内部一个点到n个顶点的距离, 让你求出这个多边形的边长. 二分边长, 然后用余弦定理求出给出的相邻的两个边之间的夹角, 看所有的加起来是不是2Pi. # ...
- (Problem 19)Counting Sundays
You are given the following information, but you may prefer to do some research for yourself. 1 Jan ...
- 编程习题——Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- canvas 基础知识
canvas 基础 低版本的ie不支持html5,需要引入excanvas.js来让ie支持canvas. 检测支持canvas <canvas id="canvas" wi ...
- ubuntu 常用生产环境部署配置测试调优
1,ubuntu monogdb 安装配置 2,ubuntu jdk1.7,tomcat7安装 3,ubuntu LAMP部署 4,mongodb 远程热备份及恢复 使用自带的mongodump和mo ...
- 取得phpcms网站下所有栏目的内容链接
今天做了一个小功能,就是取得公司网站的所有文章的内容地址,公司网站是用phpcms 做的,感觉还蛮简单的,记录下: <?php $conf['DB_USER'] = 'user'; $conf[ ...
- 深入了解epoll (转)
一. 介绍 Epoll 是一种高效的管理socket的模型,相对于select和poll来说具有更高的效率和易用性.传统的select以及poll的效率会因为 socket数量的线形递增而导致呈二次乃 ...