Codeforces Round #630 (Div. 2)

Topic links: https://codeforces.com/contest/1332

A. Exercising Walk

Repeatedly moving the two directions offset by the number of steps, the number of steps and see if more than or equal to a length direction of the remaining number of steps.

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

void solve()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x,y,x1,x2,y1,y2;
    cin>>x>>y>>x1>>y1>>x2>>y2;
    
    int L1 = max (X-X1, X2-X), L2 = max (Y2-Y, Y- Y1);
     IF (L1> 0 ) { // if the left or right away 
        int mi The min = (A , B); // move around cancel each 
        A- = mi The, B- = mi The;
         IF (A> 0 && A <= X-X1) A = 0 ;
         IF (B> 0 && B <= X-X2) = B 0 ;
    }

    if(l2>0){
        int mi=min(c,d);
        c-=mi,d-=mi;
        if(c>0&&c<=y-y1) c=0;
        if(d>0&&d<=y2-y) d=0;
    }

    if(a||b||c||d) cout<<"No\n";
    else cout<<"Yes\n";
}

int main ()
{
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}
View Code

B. Composite Coloring

Only less than 1000 square prime factor 11, the same dye color to a minimum prime factor.

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

void solve()
{
    int n;cin>>n;
    int res[n]={};

    int color=0;
    map<int,int> m;
    
    for ( int I = 0 ; I <n-; I ++ ) {
         int T; CIN >> T;
         for ( int J = 2 ; J <= T; J ++ ) {
             IF (T% J == 0 ) {
                 IF (m [J]) RES [I] = m [J]; // if this occurs before the quality factor, the number of the same color to dye 
                the else RES [I] = m [J] color = ++; // otherwise give the quality factor is assigned a new color 
                BREAK ;
            }
        }
    }

    cout<<color<<"\n";
    for(int i=0;i<n;i++) cout<<i<<" \n"[i==n-1];
}

int main ()
{
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}
View Code

C. K-Complete Word

Each taking both ends of the character and inward ends of period characters, which are to be the same, which replaced most of that on it.

#include <bits/stdc++.h>
using namespace std;
 
void solve()
{
    int n,k;cin>>n>>k;
    string s;cin>>s;

    int years = 0 ;
    bool am [n] = {};

    for(int i=0;i<n;i++)
    {
        if(vis[i]) continue;
        vector<char> v;

        for(int j=i;j<n;j+=k)
            if(!vis[j]){
                v.push_back(s[j]);
                vis[j]=true;
            }
        for(int j=n-i-1;j>=0;j-=k)
            if(!vis[j]){
                v.push_back(s[j]);
                vis[j]=true;
            }
            
        int cnt[26]={};
        for(char c:v) cnt[c-'a']++;
        int mx=*max_element(cnt,cnt+26);
        ans+=int(v.size())-mx;
    }

    cout<<ans<<"\n";
}
 
int main ()
{
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}
View Code

D. Walk on Matrix

The original dp code because of the pursuit of maximum current value and discard lower value will make a greater answer, you can construct the same ideas.

#include <bits/stdc++.h>
using namespace std;
const int inf=1<<17;
int main()
{
    int k;cin>>k;
    cout<<"2 3\n";
    cout<<(inf+k)<<' '<<k<<' '<<inf<<"\n";
    cout<<inf<<' '<<(inf+k)<<' '<<k;
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/Kanoon/p/12609890.html