Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

Keywords: iOS

Competition Address:

http://codeforces.com/contest/1025

A Title:

Title: Give you a string of strings, which requires that the string be changed into the same letter after a certain number of operations. The operation is to select a letter x (which must appear more than once in the string), and then change all the x into y (any letter) in the string. This operation can be carried out indefinitely. Ask if you can fulfill the requirement, you can output "Yes" or "No".

Thought: After reading the meaning of the title, it is easy to think that as long as there is a letter x in the string (more than one occurrence in the string), then you can complete the requirements, and then quickly complete the code, passed the sample, handed in, the result wa, momentarily confused, analyzed, found that my method is not a problem, so almost no change, with luck, and handed in again. First, the result is wa, then according to debug summary of my previous article, I checked the output format, found that there is no case discrimination, and then changed and handed in again, the result is wa. Then I guess there may be a limited situation without consideration. Looking at the status of submission, I found that many people like me wa in the fourth example, so it is almost certain that the fourth example is wa. A special example. Then, following debug's summary, I began to think about the limit case, only to find the special case when a string has only one letter. After the change, a.

Summary: The first three was are totally avoidable, as long as I follow the debug summary and check all the steps at once, then a. This also reminds me that when wa comes to the end, there may be more than one mistake. We must try our best to correct it.

Code:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#define Fin             freopen("in.txt","r",stdin)
#define Fout            freopen("out.txt","w",stdout)
#define Case(T)         int T;for(scanf("%d",&T);T--;)
#define fo(i,a,b)              for(int i = a; i < b; ++i)
#define fd(i,a,b)              for(int i = a; i >= b; --i)
#define me(a,b) memset(a,b,sizeof(a))
#define fi(a,n,val)    fill(a,a+n,val)
#define Scand(n)       scanf("%d",&n)
#define Scans(s)       scanf("%s",s)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b ? gcd(b,a%b): a; }
const int maxn = 1e6 + 5;
const int INF = 0xffffff;

#ifndef ONLINE_JUDGE

#endif // ONLINE_JUDGE

int n;
char s[maxn];
int vis[100];

int main()
{
#ifndef ONLINE_JUDGE
    //Fin;
#endif // ONLINE_JUDGE
    cin >> n;
    Scans(s);
    if(n == 1){
        cout << "YES" << endl;
        return 0;
    }
    fo(i, 0, n){
        vis[s[i]-'a']++;
        if(vis[s[i]-'a'] >= 2){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

B Title:

The meaning of the title: Give you n pairs, each pair, two numbers, let you find a number, it is the common number of each pair, where the common number is redefined, if a is the approximate number of (x,y) pairs, as long as a is the approximate number of x,y is OK.

Thought: Because the title is Weakened Common Divisor, associating with the common divisor of two numbers, but here are some common divisors of pairs. I wonder if I can convert a pair into a number and multiply the two numbers. Because I guess, I haven't tried it. After reading other people's solutions, I find that this idea is feasible. Paste the code directly.

Code:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#define Fin             freopen("in.txt","r",stdin)
#define Fout            freopen("out.txt","w",stdout)
#define Case(T)         int T;for(scanf("%d",&T);T--;)
#define fo(i,a,b)              for(int i = a; i < b; ++i)
#define fd(i,a,b)              for(int i = a; i >= b; --i)
#define me(a,b) memset(a,b,sizeof(a))
#define fi(a,n,val)    fill(a,a+n,val)
#define Scand(n)       scanf("%d",&n)
#define Scans(s)       scanf("%s",s)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b ? gcd(b,a%b): a; }
const int maxn = 110000 + 5;
const int INF = 0xffffff;

#ifndef ONLINE_JUDGE

#endif // ONLINE_JUDGE

int n;
ll a,b;


int main()
{
 //   ios::sync_with_stdio(false);cin.tie(0);
#ifndef ONLINE_JUDGE
    //Fin;
#endif // ONLINE_JUDGE
    cin >> n;
    cin >> a >> b;
    fo(i, 1, n){
        ll c,d;
        cin >> c >> d;
        ll e = c*d;
        a = gcd(a, e);
        b = gcd(b, e);
    }
//    printf("a:%lld b:%lld\n",a,b);
    if(a == 1 && b == 1)
        cout << -1 << endl;
    else{
        for(ll i=2; i*i <= a || i*i <= b; ++i)
            if(a%i == 0 || b%i == 0){
                cout<<i<<endl;
                return 0;
            }
        if(a != 1)
            cout << a << endl;
        else
            cout << b << endl;
    }
    return 0;
}

C Title:

Title:

Give you a string of strings. Ask you how long the longest zebra crossing is after many operations. The so-called zebra crossing is a string of 01 strings, that is, bwbw or wbwbw in the title. What you can do is to find a splitting point in the string and invert the strings on both sides, such as BW w BW w | BW w w BW w WB | WB w | WB WB WB w w BW WB w BW BW w BW w w. The answer to this example is 5

Thought: Because it involves finding a partition point in a string, and inversion, associating with "ring", it is found that as long as the longest 01 string is found in the ring, then the original string s can be doubled into s+s, and a ring can be simulated.

Since it involves transformation, it is important to note that the answers obtained after transformation are beyond the scope of the original series. There is a wa point in this question, that is, the final answer will not exceed the length of the original string.

Code:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#define Fin             freopen("in.txt","r",stdin)
#define Fout            freopen("out.txt","w",stdout)
#define Case(T)         int T;for(scanf("%d",&T);T--;)
#define fo(i,a,b)              for(int i = a; i < b; ++i)
#define fd(i,a,b)              for(int i = a; i >= b; --i)
#define me(a,b) memset(a,b,sizeof(a))
#define fi(a,n,val)    fill(a,a+n,val)
#define Scand(n)       scanf("%d",&n)
#define Scans(s)       scanf("%s",s)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b ? gcd(b,a%b): a; }
const int maxn = 1e6 + 50;
const int INF = 0xffffff;

#ifndef ONLINE_JUDGE

#endif // ONLINE_JUDGE

//char s[maxn];

int main()
{
 //   ios::sync_with_stdio(false);cin.tie(0);
#ifndef ONLINE_JUDGE
    //Fin;
#endif // ONLINE_JUDGE
//    Scans(s);
//    char *ss = strcat(s, s);
//    int len1 = strlen(s);
//    int len2 = strlen(ss);
    string s,ss;
    cin >> s;
    int len1 = s.length();
    ss = s+s;
    int len2 = ss.length();
    ll cnt = 1;
    ll ans = -1;
    fo(i, 1, len2){
        if(ss[i] != ss[i-1])
            cnt++;
        else{
            ans = cnt > ans ? cnt : ans;
            cnt = 1;
        }
    }
    ans = cnt > ans ? cnt : ans;
   // printf("ans:%lld\n",ans);
    ans = len1 < ans ? len1 : ans;
    cout << ans << endl;
    return 0;
}

Finally: No one is born to be the bottom, and no one is born to be a vegetable!

Posted by k9underdog on Sat, 05 Jan 2019 09:24:08 -0800