CodeForces-508A~D篇 div.2

链接:https://codeforc.es/contest/1038

A题:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 #define PI acos(-1.0)
 5 typedef pair<int,int> P;
 6 const int INF=0x3f3f3f3f;
 7 map<int,int> mp;
 8 int a[100010];
 9 int main()
10 {
11     ios::sync_with_stdio(false);
12     int n,k;
13     string s;
14     cin>>n>>k;
15     cin >> s;
16    int len = 0;
17    int ans = INF;
18    for(int i=0;i<n;i++) a[i] = s[i] - 'A',mp[a[i]]++;
19    for (int i = 0; i < k; i++) ans = min(ans, mp[i]);
20    cout << ans * k << endl;
21     
22     return 0;
23 }
View Code

B题:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 #define PI acos(-1.0)
 5 typedef pair<int,int> P;
 6 const int maxn=0x3f3f3f3f;
 7 
 8 int main()
 9 {
10     ios::sync_with_stdio(false);
11     int n;
12     cin>>n;
13     if(n<=2) cout<<"No"<<endl;
14     else 
15     {
16         cout<<"Yes"<<endl;
17         cout<<n-(n+1>>1);
18         for(int i=2;i<=n;i+=2) cout<<" "<<i;
19         cout<<endl;
20         cout<<(n+1>>1);
21         for(int i=1;i<=n;i+=2) cout<<" "<<i;
22         cout<<endl;
23         
24     }
25     return 0;
26 }
View Code

C题:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 #define PI acos(-1.0)
 5 typedef pair<int,int> P;
 6 const int INF=0x3f3f3f3f;
 7 const int maxn=1e6+10;
 8 int n;
 9 LL a[maxn],b[maxn],sum1,sum2;
10 int main()
11 {
12     ios::sync_with_stdio(false);
13     cin>>n;
14     sum1=sum2=0;
15     for(int i=1;i<=n;i++) cin>>a[i];
16     for(int i=1;i<=n;i++) cin>>b[i];
17     sort(a+1,a+1+n); sort(b+1,b+1+n);
18     //for(int i=1;i<=n;i++) cout<<a[i]<<" "<<b[i]<<endl;
19     int flag1=n,flag2=n;
20     while(1)
21     {
22         if(a[flag1]<=b[flag2]) flag2--;
23         else sum1+=a[flag1],flag1--;
24         if(flag2==0)
25         {
26             sum1+=a[flag1];
27             break;
28         }
29         else if(flag1==0)
30         {
31             sum2+=b[flag2];
32             break;
33         }
34         if(b[flag2]<=a[flag1]) flag1--; 
35         else sum2+=b[flag2],flag2--;
36         if(flag2==0)
37         {
38             sum1+=a[flag1];
39             break;
40         }
41         else if(flag1==0)
42         {
43             sum2+=b[flag2];
44             break;
45         }
46     }
47     cout<<sum1-sum2<<endl;
48     return 0;
49 }
View Code

D题:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 #define PI acos(-1.0)
 5 typedef pair<int,int> P;
 6 const int maxn=5e5+10;
 7 int n;
 8 LL a[maxn];
 9 int main()
10 {
11     ios::sync_with_stdio(false);
12     
13     cin>>n;
14     for(int i=1;i<=n;i++) cin>>a[i];
15     if(n==1) cout<<a[1]<<endl;
16     else
17     {
18         sort(a+1,a+1+n);
19         LL ans=0;
20         ans=abs(a[1]-a[n]);
21         for(int i=2;i<n;i++) ans=ans+abs(a[i]);
22         cout<<ans<<endl;
23     }
24     
25     return 0;
26 }
View Code

 

posted @ 2018-09-09 21:30  StarHai  阅读(318)  评论(0编辑  收藏  举报