zoukankan      html  css  js  c++  java
  • BestCoder Round #61 (div.2)

    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}A1​​,A2​​....An​​,your task is to check whether there exists there different positive integers i, j, k (1≤i,j,k≤n1leq i , j , k leq n1i,j,kn) such that Ai−Aj=Ak{A}_{i}-{A}_{j}={A}_{k}Ai​​Aj​​=Ak​​

    Input

    There are multiple test cases, no more than 1000 cases. First line of each case contains a single integer n.(3≤n≤100)(3leq nleq 100)(3n100). Next line contains n integers A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A1​​,A2​​....An​​.(0≤Ai≤1000)(0leq {A}_{i}leq 1000)(0Ai​​1000)

    Output

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

    Sample Input
    3
    3 1 2
    3
    1 0 2
    4
    1 1 0 2
    Sample Output
    YES
    NO
    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=1010;
    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,0,sizeof(cnt));
    18         for(int i=0;i<n;i++){
    19             scanf("%d",m+i);
    20             st.insert(m[i]);
    21             cnt[m[i]]++;
    22         }
    23         int su,flot=0;
    24         for(int i=0;i<n;i++){
    25         for(int j=i+1;j<n;j++){
    26             su=m[i]+m[j];
    27             if(su==m[i]||su==m[j]){
    28                 if(cnt[su]==1)continue;
    29             }
    30             if(m[i]==m[j]&&m[i]==su){
    31                 if(cnt[su]==2)continue;
    32             }
    33             if(st.count(su)){
    34                 flot=1;
    35                 break;
    36             }
    37         }
    38         if(flot)break;
    39         }
    40         if(flot)puts("YES");
    41         else puts("NO");
    42     }
    43     return 0;
    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)(1leq Nleq10000,1leq S,Tleq N )(1N10000,1S,TN)

    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
    4 1 4
    4 1 3
    Sample Output
    0
    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>0?x:-x;
    11 }
    12 int main(){
    13     int N,S,T;
    14     while(~scanf("%d%d%d",&N,&S,&T)){
    15         if(N==1)puts("0");
    16         else if(S==T)puts("-1");
    17         else if(S==1||S==N){
    18             if(T==1||T==N)puts("0");
    19             else puts("1");
    20         }
    21         else if(T==1||T==N){
    22             if(FABS(T-S)==1)puts("1");
    23             else
    24                 puts("2");
    25         }
    26         else{
    27              if(FABS(T-S)==1)puts("1");
    28             else
    29                 puts("2");
    30         }
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    shiro cookie登录根据角色跳转不同页面的解决方案
    springboot 引入shiro缓存及rememberMe支持
    android开发记录2 webview调用二维码扫描
    android app开发记录1
    bootstrap datetimepicker 出现选中后没有日期的原因
    mybatis-plus @Select select in 查询实现
    Mybatis-Plus 中的 @Select 出现查询不到数据的原因
    caffe Python API 之InnerProduct
    caffe Python API 之LRN
    caffe Python API 之Dropout
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4926356.html
Copyright © 2011-2022 走看看