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: ...
随机推荐
- 单选,复选操作div,显示隐藏
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- 根据用户的ID查用户的名字
awk -F: '{if($3==0){print $1}}' /etc/passwd
- 解决Thinkpad E450 外接显示器后没有声音的问题
昨天把公司配的ThinkPad E450 带回来了,今天用的时候一切正常没什么问题. 因为要看边看视频边做点别的,我就外接一台显示器,说出来我的这台显示器,你们绝对想不到是什么 显示器.我的这台显示器 ...
- C#学习日志 day 2 ------ 控制台颜色以及windowsphone 窗体应用试建
成功跑起来了hello之后,试试改变背景颜色.
- 利用python进行数据分析之数据加载存储与文件格式
在开始学习之前,我们需要安装pandas模块.由于我安装的python的版本是2.7,故我们在https://pypi.python.org/pypi/pandas/0.16.2/#downloads ...
- maven 常用命令及操作(转)
Maven库: http://repo2.maven.org/maven2/ Maven依赖查询: http://mvnrepository.com/ Maven常用命令: 1. 创建Maven的普通 ...
- shell实现死循环
参考自http://codingstandards.iteye.com/blog/780524 .while true do command; done .while : do command; do ...
- 串的模式匹配——Brute-Force算法
Brute-Force算法的基本思路为:从目标串s=“s0s1...sn-1”的第一个字符开始和模式串t=“t0t1t2...tn-1”中的第一个字符比较,若相等,则继续逐个比较后续字符: 否则从目标 ...
- 解决Windows 程序界面闪烁问题的一些经验
原帖地址:http://blog.joycode.com/yaodong/archive/2004/11/26/39764.aspx 一般的windows 复杂的界面需要使用多层窗口而且要用贴图来美化 ...
- Struts 和Spring的核心控制器
Struts 核心控制器是FilterDispatch Spring核心控制器是DispatchServlet