首页 > 代码库 > Codeforces Round #411 (Div. 2)

Codeforces Round #411 (Div. 2)

A题

分析:傻逼题,两个数的差不大于1输出任意一个,否则输出2

技术分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "cmath"
 5 using namespace std;
 6 int main()
 7 {
 8     long long a,b;
 9     while(cin>>a>>b)
10     {
11         if(abs(a-b)<=1)
12             cout<<a<<endl;
13         else
14             cout<<"2"<<endl;
15     }
16     return 0;
17 }
View Code

B题

分析:还是傻逼题,只要输出aabb不断循环下去就行

技术分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "cmath"
 5 using namespace std;
 6 int n;
 7 int main()
 8 {
 9     while(cin>>n)
10     {
11         int ans=n/4;
12         string a="aabb";
13         for(int i=1;i<=ans;i++)
14             cout<<a;
15         int cnt=n%4;
16         for(int i=0;i<cnt;i++)
17             cout<<a[i];
18         cout<<endl;
19     }
20     return 0;
21 }
View Code

C题

分析:经推到为(n-1)/2

技术分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 using namespace std;
 5 long long n;
 6 int main()
 7 {
 8     while(cin>>n)
 9         cout<<(n-1)/2<<endl;
10 }
View Code

D题

分析:最终都会转换为bbbaa...这样的形式,倒着推一下就有了

技术分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "string"
 5 #include "cmath"
 6 using namespace std;
 7 const int mod=1000000007;
 8 const int maxn=100010;
 9 string s;
10 long long vis[100010];
11 int main()
12 {
13     cin>>s;
14         int len=s.length();
15         long long m,l,k,ans,numa,numb;
16         numa=0;
17         numb=0;
18         ans=0;
19         for(int i=len-1;i>=0;i--)
20         {
21             if(s[i]==a)
22                 numa++;
23             if(s[i]==b)
24                 numb++;
25             if(s[i]==a && numb>0)
26             {
27                 ans=(ans+numb)%mod;
28                 numb=(numb*2)%mod;
29             }
30         }
31         cout<<ans<<endl;
32     return 0;
33 }
View Code

 

Codeforces Round #411 (Div. 2)