Codeforces Round #410 (Div. 2)

A题

分析:把串反转,判不一样的个数,不同个数恰好为2个或者为0个且串的长度为奇数就输出YES,否则为NO

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cmath"
 4 #include "cstring"
 5 using namespace std;
 6 string s;
 7 void Rev(string &str){
 8     int i=0,j=str.length()-1;
 9     while(i<j){
10         swap(str[i],str[j]);
11         i++,j--;
12     }
13 }
14 int main()
15 {
16     while(cin>>s){
17         string p="";
18         for(int i=0;i<s.length();i++)
19             p+=s[i];
20         Rev(p);
21         int cnt=0;
22         int n=s.length();
23         for(int i=0;i<n;i++){
24             if(s[i]!=p[i])
25                 cnt++;
26         }
27         if(cnt==2||((n%2)&&cnt==0))
28             cout<<"YES"<<endl;
29         else
30             cout<<"NO"<<endl;
31     }
32 }

B题

C题

分析:如果gcd>1则直接输出YES,0.否则其他情况,我们考虑把他全变成偶数所需要的最少操作。如果a[i],a[i+1]全是奇数,则只需要一次操作即可,如果a[i],a[i+1]一奇一偶,则需要两次变化,最后直接统计即可。

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "algorithm"
 4 #include "cstring"
 5 using namespace std;
 6 const int maxn=100000+10;
 7 long long a[maxn],b[maxn];
 8 int n;
 9 long long gcd(long long a,long long b){
10     if(b==0)  return a;
11     return gcd(b,a%b);
12 }
13 int main()
14 {
15     while(cin>>n)
16     {
17         cin>>a[0]>>a[1];
18         long long g=gcd(a[0],a[1]);
19         for(int i=2;i<n;i++){
20             cin>>a[i];
21             g=gcd(g,a[i]);
22         }
23         if(g>1){
24             cout<<"YES"<<endl;
25             cout<<"0"<<endl;
26             continue;
27         }
28         long long cnt=0;
29         for(int i=0;i<n-1;i++){
30             if(a[i]%2==0)  continue;
31             if((a[i]%2)&&(a[i+1]%2)){
32                 a[i]=2,a[i+1]=2;
33                 cnt++;
34                 continue;
35             }
36             cnt+=2;
37             a[i]=2,a[i+1]=2;
38         }
39         if((a[n-2]%2==0)&&(a[n-1]%2))
40             cnt+=2;
41         cout<<"YES"<<endl;
42         cout<<cnt<<endl;
43     }
44 }

时间: 2024-08-07 12:24:48

Codeforces Round #410 (Div. 2)的相关文章

Codeforces Round #410 (Div. 2)-A - Mike and palindrome

题目简述:给定一个字符串判断是否能够恰好改变一个字符使其变成回文(回文:eg.abcba或abccba). 注意:1,是恰好改变一个字符,恰好! 2,字符串例如"abc"这样的奇数个数的而且是完整回文的字符串也是可以恰好改变一个字符变成回文的(改变最中间的那个字符,中间的那个字符改成什么都是回文) 我当时就卡死在这个坑. 我的代码是用栈做的虽然有点蠢...当时我都不知道for居然可以放两个入口变量,那样的话i++,j--就成了,我着急直接用栈,我居然不知道栈没有迭代器,也没注意上述注意

[卿学姐带飞系列]-Codeforces Round #410 (Div. 2)_B - Mike and strings

1 #include<bits/stdc++.h> 2 #define inf 0x3f3f3f3f 3 using namespace std; 4 const int maxn=55; 5 string s[maxn]; 6 int main() 7 { 8 int n; 9 cin>>n; 10 for(int i=0;i<n;i++){ 11 cin>>s[i]; 12 } 13 int ans=inf,tem; 14 for(int i=0;i<s

Codeforces Round #410 (Div. 2)C. Mike and gcd problem(数论)

传送门 Description Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. . Mike wants to change his sequence in order to make it beautiful.

Codeforces Round #410 (Div. 2) 解题报告

A. 因为A的题意导致这次罚时比较多--注意change一定是必须得改成不一样的,如a改成a是不行的. 1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <queue> 8 #include <se

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除