码迷,mamicode.com
首页 > 其他好文 > 详细

BestCoder Round #61 (div.2)

时间:2015-10-31 23:01:50      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

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 n1i,j,kn) 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)(3n100). 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)(0A?i??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)(1\leq N\leq10000,1\leq S,T\leq 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 }

 

BestCoder Round #61 (div.2)

标签:

原文地址:http://www.cnblogs.com/handsomecui/p/4926356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!