Numbers

Accepts: 571
Submissions: 1212
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/262144 K (Java/Others)
Problem Description

There are n numbers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​,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}A​i​​−A​j​​=A​k​​

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}A​1​​,A​2​​....A​n​​.(0≤Ai≤1000)(0\leq {A}_{i}\leq 1000)(0≤A​i​​≤1000)

Output

For each case output "YES" in a single line if you find such i, j, k, otherwise output "NO".

Sample Input
  1. 3
  2. 3 1 2
  3. 3
  4. 1 0 2
  5. 4
  6. 1 1 0 2
Sample Output
  1. YES
  2. NO
  3. YES
    题解:刚开始用vector写的,发现原来没有count。。。就改成了;
    代码:
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<set>
  7. using namespace std;
  8. const int INF=0x3f3f3f3f;
  9. const int MAXN=;
  10. int m[MAXN];
  11. int cnt[MAXN];
  12. set<int>st;
  13. int main(){
  14. int n;
  15. while(~scanf("%d",&n)){
  16. st.clear();
  17. memset(cnt,,sizeof(cnt));
  18. for(int i=;i<n;i++){
  19. scanf("%d",m+i);
  20. st.insert(m[i]);
  21. cnt[m[i]]++;
  22. }
  23. int su,flot=;
  24. for(int i=;i<n;i++){
  25. for(int j=i+;j<n;j++){
  26. su=m[i]+m[j];
  27. if(su==m[i]||su==m[j]){
  28. if(cnt[su]==)continue;
  29. }
  30. if(m[i]==m[j]&&m[i]==su){
  31. if(cnt[su]==)continue;
  32. }
  33. if(st.count(su)){
  34. flot=;
  35. break;
  36. }
  37. }
  38. if(flot)break;
  39. }
  40. if(flot)puts("YES");
  41. else puts("NO");
  42. }
  43. return ;
  44. }

Game

Accepts: 0
Submissions: 2320
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
Problem Description

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.

Input

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)

Output

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.

Sample Input
  1. 4 1 4
  2. 4 1 3
Sample Output
  1. 0
  2. 1
    题解:各种判断。。。
    代码:
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<set>
  7. using namespace std;
  8. const int INF=0x3f3f3f3f;
  9. int FABS(int x){
  10. return x>?x:-x;
  11. }
  12. int main(){
  13. int N,S,T;
  14. while(~scanf("%d%d%d",&N,&S,&T)){
  15. if(N==)puts("");
  16. else if(S==T)puts("-1");
  17. else if(S==||S==N){
  18. if(T==||T==N)puts("");
  19. else puts("");
  20. }
  21. else if(T==||T==N){
  22. if(FABS(T-S)==)puts("");
  23. else
  24. puts("");
  25. }
  26. else{
  27. if(FABS(T-S)==)puts("");
  28. else
  29. puts("");
  30. }
  31. }
  32. return ;
  33. }

BestCoder Round #61 (div.2)的更多相关文章

  1. BestCoder Round #61 (div.2) C.Subtrees dfs

    Subtrees   问题描述 一棵有N个节点的完全二叉树,问有多少种子树所包含的节点数量不同. 输入描述 输入有多组数据,不超过1000组. 每组数据输入一行包含一个整数N.(1\leq N\leq ...

  2. BestCoder Round #61 (div.2) B.Game 细节题

    Game   问题描述 XY在玩一个游戏:有N根柱子排成一排,编号为1到N,每个柱子上面有一块宝石,现在XY站在第S根柱子上,出口在第T跟柱子上,XY需要拿到所有宝石后从出口离开.每次XY可以走到相邻 ...

  3. HDU5526/BestCoder Round #61 (div.1)1004 Lie 背包DP

    Lie   问题描述 一个年级总共有N个学生,每个人属于唯一一个班级.现在他们站在一排,同班同学并不一定会站在一起,但每个人都会说一句话:“站在我左边的有Ai个同班同学,右边有Bi个同班同学”.然而并 ...

  4. 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 ( ...

  5. 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 ...

  6. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  7. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

  8. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  9. hdu5634 BestCoder Round #73 (div.1)

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. [vc]如何对radio按钮分组

    如何使用多组? 多组和一组是一样的使用,只要搞清楚哪个是哪一组的就行了.再为对话框添加Radio3和Radio4.很简单,先为这些RadioButton排个顺序,就是排列他们的TABORDER.在对话 ...

  2. bootstrap你让前端小狮子们又喜又恨

    看了一个用bootstrap框架建的页面,简直方便至极!各种添加类就可以实现各种功能,各种添加data-toggle让你不需要懂javascript就可以做出很炫的效果! 最重要的它做出来的页面还是响 ...

  3. 64bits Python2.7.5安装numpy包

    由于数值分析需要numpy计算包,我找了很多numpy-cp27的下载地址,下了最新版的.whl文件,但总是安装不成功,后来找到一个.exe文件 直接下载安装即可使用:下面是网址链接http://do ...

  4. protel99与win7兼容问题的解决方案

    一些用户大概都已经把自己的 PC 从 winXP 换到了 win7,在 win7 给我们带来的视觉上的冲击和功能上的更换.也不时的带来了各方面的软件兼容问题 ,而一般上的兼容都可以在 win7 的自动 ...

  5. Delphi 重启应用程序(创建Bat文件的Process)

    Delphi 重启应用程序在工程主文件中加入Delay(500); //启动程序时请延时一段时间,否则只能重启一次 procedure RestartApp; var BatchFile: TextF ...

  6. Html 小插件5 百度搜索代码2

    网页添加百度搜索框代码大全 ★ 用法:在下面选择合适的样式,复制代码到网页中相应位置粘贴即可. ★ 样式一(200×30)代码: <iframe id="baiduframe" ...

  7. vb.net 操作xml

    xml文件: <?xml version="1.0" encoding="gb2312"?> <bookstore> <book ...

  8. zookeeper 伪集群模式

    问题二:开发没有足够机器,一台机子上是否装三个zookeeper服务器集群. 问题解答: 这种安装模式只能说是一种伪集群模式.三个zookeeper服务器都安装在同一个服务器(platform)上,需 ...

  9. php在apache中运行模式

    php在apache中运行模式 (2011-12-18 02:38:27) 标签: 杂谈 分类: 服务器及软件 一.php在php在三种工作方式:Apache 模块DLL) 以下分别比较: 1. ph ...

  10. 7kb的javascript日期操作类库(XDate)

    A Modern JavaScript Date Library XDate is a thin wrapper around JavaScript's native Date object that ...