其他分享
首页 > 其他分享> > cf627 div3

cf627 div3

作者:互联网

 

 

 题意 :

可以选择任意一个数 + 2

当所有的数都>0时,都 -1

最后你能否都变成 0

先排序 ,比较相邻两个数字的差 ,如果有一个时奇数,说明是不可以

都为偶数,可以
View Code

 

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int t,n,a[105],g,f;
 4 int main(){
 5     //freopen("in","r",stdin);
 6     ios::sync_with_stdio(0);
 7     cin >> t;
 8     while(t--){
 9         f = 0;
10         cin >> n;
11         for(int i = 1; i <= n; i++)
12             cin >> a[i];
13  
14         for(int i = 2; i <= n; i++){
15             g = abs(a[i] - a[i - 1]);
16             if(g & 1){
17                 cout << "NO" << endl;
18                 f = 1;
19                 break;
20             }
21         }
22         if(!f) cout << "YES" << endl;
23     }
24     return 0;
25 }
View Code

 

 

 

 

 题意:

找长度至少为3的回文串

题目中说了,[1,2,1,3]的子串是[2]  [1,2,1,3 ] [2,3] 也就是说不用必须连续

长度为3的回文串 比如 1 1 1 或者 1 2 1 或者 1 2 2 1

第一个表示 3个相同的数字

第二个表示 两个不相邻的相同数字

第三种表示 2 个相同的数字 中间还有两个相同的数字

第三种进一步 去掉一个2可以变成第二种 再看 1 1 1 和 1 2 1

也就是说只要不相邻的数字 相等即可
View Code

 

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 5;
int t,n,a[maxn];
int flag;
int main(){
   // freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> t;
    while(t--){
        flag = 0;
        cin >> n;
        for(int i = 0; i < n; i++)
            cin >> a[i];

        for(int i = 0; i < n - 2; i++){
            for(int j = i + 2; j < n; j++){
                if(a[i] == a[j]){
                    flag = 1;
                    break;
                }
            }
            if(flag) break;
        }
        if(flag)
            cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}
View Code

 

 

 

 题意:

t组样例

每组一个字符串 只有L<R组成

字符串从1到n

青蛙从0开始,能到n + 1 的最大的d

如果是L,王座  R 往右

青蛙不能走L,只能走R

两个连续的R之间的最大距离
View Code

 

#include <bits/stdc++.h>
using namespace std;

int t,ans;
string s;
int main(){
    //freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> t;
    while(t--){
        ans = 0;
        cin >> s;
        int l = s.size();
        s[l] = 'R';
        int pos = l;
        for(int i = l - 1; i >= 0; i--){
            if(s[i] == 'R'){
                ans = max(ans,pos - i);
                pos = i;
            }
        }
        if(s[0] != 'R')
            ans = max(ans,pos + 1);
        cout << ans << endl;
    }
    return 0;
}
View Code

 

标签:Code,int,cin,flag,ans,cf627,div3,View
来源: https://www.cnblogs.com/xcfxcf/p/12496435.html