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: ...
随机推荐
- C#反序列化json字符串时,提示:应为来自命名空间“”的元素“root”。。遇到名称为“”、命名空间为“”的“None”。
反序列化调用接口返回的字符串时,出现:应为来自命名空间“”的元素“root”..遇到名称为“”.命名空间为“”的“None”.,导致反序列化数据失败,这种失败并有时候并不会直接提示反序列化失败(抛异常 ...
- Struts2拦截器总结
拦截器的本质: 拦截器就是一个类,一个实现了超级接口Interceptor的类.Interceptor接口里定义了三个方法 init(),destory(),intercept().其中inercep ...
- 监听器和web国际化
一.监听器 1.监听器:监听器就是一个java程序,功能是监听另一个java对象变化(方法调用.属性变更) 2.监听器监听过程:事件源.事件对象.监听器对象.操作事件源 1).存在被监听对象(事件源) ...
- poj 1949 Chores 最长路
题目链接 求出最长路..... #include <iostream> #include <vector> #include <cstdio> #include & ...
- JavaScript 鸭子模型
Javascript:由 “鸭子类型” 得出来的推论 背景 学动态语言的都知道一句话:“如果它走起来像鸭子,而且叫起来像鸭子,那么它就是鸭子”,Javascript也支持鸭子类型,下文就说说鸭子类型在 ...
- Oracle 数据库导入、导出
第一步:新建一个txt文件: exp.exe jeamsluu@test file=d:\daochu.dmp log=1.log 另存为.bat格式的文件 第二步:双击运行:此时会弹出输入口令的对话 ...
- STL"源码"剖析
STL"源码"剖析-重点知识总结 STL是C++重要的组件之一,大学时看过<STL源码剖析>这本书,这几天复习了一下,总结出以下LZ认为比较重要的知识点,内容有点略 ...
- MySQl5.6最新安装
http://www.cnblogs.com/xiongpq/p/3384681.html http://dev.mysql.com/doc/refman/5.5/en/source-configur ...
- .NET(C#):在数组成员上加入XmlElement特性
原文 www.cnblogs.com/mgen/archive/2011/12/04/2276131.html 当对如下类进行XML序列化时: publicclassa { }; } 结果会是: &l ...
- Android Activity和Fragment传递数据
1.Activity与Activity传递数据 UserLoginActivity.java: Intent welcomePage = new Intent(); Bundle dataBundle ...