Codeforces Round #436 (Div. 2)

传送门: http://codeforces.com/contest/864
 
 
A. Fair Game
题意:给你一个数组,判断里面是否只有两个重复的整数,个数也要相等。
 1 include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <string>
 5 #include <map>
 6 #include <algorithm>
 7 using namespace std;
 8 
 9 int main()
10 {
11     ios::sync_with_stdio(0);
12     int n;
13     int a[220];
14     cin>>n;
15     for(int i=0; i<n; i++){
16         cin>>a[i];
17     }
18     sort(a, a+n);
19     if(a[0] == a[n/2-1] && a[n/2] == a[n-1] && a[0] != a[n-1]){
20         cout<<"YES"<<endl;
21         cout<<a[0]<<" "<<a[n-1]<<endl;
22     }
23     else{
24         cout<<"NO"<<endl;
25     }
26     return 0;
27 }
View Code
 
B. Polycarp and Letters
题意:以字符串中大写字母为分割,然后在剩下的字符串中的找出有不同的小写字母最多的串,输出这个串中的小写字母的个数。
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <string>
 5 #include <map>
 6 #include <set>
 7 #include <algorithm>
 8 using namespace std;
 9 
10 int main()
11 {
12     ios::sync_with_stdio(0);
13     string s;
14     set<char>st;
15     int len, max = 0;
16     cin>>len;
17     cin>>s;
18     for(int i=0; i<len; i++){
19         if(s[i]>='A' && s[i]<='Z'){
20             st.clear();
21         }
22         else{
23             st.insert(s[i]);
24         }
25         max = max<st.size() ? st.size() : max;
26     }
27     cout<<max<<endl;
28     return 0;
29 }
View Code

 

C. Bus
题意:一辆小车不断在两地之间往返k次,两地之间有一个加油站。小车行驶一单位距离消耗一单位汽油。问小车能否往返k次。
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <string>
 5 #include <map>
 6 #include <set>
 7 #include <algorithm>
 8 
 9 using namespace std;
10 typedef long long LL;
11 
12 int main()
13 {
14     ios::sync_with_stdio(0);
15     LL a,b,f,k;
16     cin>>a>>b>>f>>k;
17     LL s = b,ans = 0;
18     s -= f;
19     f = a-f;
20     for(int i=k-1; i!=0; i--){
21         if(s < 0){
22             cout<<"-1"<<endl;
23             return 0;
24         }
25         else if(s < 2*f){
26             s = b;
27             ans++;
28         }
29         s = s-2*f;
30         f = a-f;
31     }
32     if(s < 0){
33         cout<<"-1"<<endl;
34         return 0;
35     }
36     if(s < f){
37         s = b;
38         ans++;
39     }
40     s = s-f;
41     if(s < 0){
42         cout<<"-1"<<endl;
43         return 0;
44     }
45     cout<<ans<<endl;
46     return 0;
47 }
View Code

 

 
 

posted on 2017-09-26 22:33  P.Lifer  阅读(112)  评论(0)    收藏  举报

导航