Codeforces Round #617 (Div.3)

A. Array with Odd Sum
It's a water problem, and if each of the array is odd, direct output YES, or to judge whether the whole array is even or all odd. If all else output NO output YES.

#include<bits/stdc++.h>
using namespace std;
int a[20200];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        int flag1=0;int flag2=0;
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            sum=sum+a[i];
            if(a[i]%2)
                flag1=1;
            else
                flag2=1;
        }
        if(sum%2!=0)
            cout<<"YES"<<endl;
        else{
            if(flag1==1&&flag2==1)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
    }
    return 0;
}

B. Food Buying
is also a water problem, in short, every time you buy 10 dollars, then simulated just fine

 #include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int s;
        cin>>s;
        int sum=0;
        int x=s;
        while(x>=10)
        {
            sum=sum+x/10*10;
            x=x%10+x/10;
        }
        sum=sum+x;
        cout<<sum<<endl;
    }
    return 0;
}

C. Yet Another Walking Robot
ideas: a map <pair <int, int> , int> traveled local storage, to a coordinate point string map index +1. If they find the next point went to have emerged in the dictionary, indicating that some way to go is in circles
count, the return is to find the number of elements. If so, return 1; otherwise, it returns 0. Note that, map does not exist in the same element, so the return value can only be 1 or 0.

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

int main()
{
    int t;
    cin>>t;
    int n;
    string s;
    while(t--)
    {
        cin>>n>>s;
        int x=0,y=0;
        map<pair<int,int>,int>m;
        int l=-1,r=n;
        m[{0,0}]=0;
        for(int i=0; i<n; i++)
        {
            if(s[i]=='L')
                x--;
            if(s[i]=='R')
                x++;
            if(s[i]=='U')
                y++;
            if(s[i]=='D')
                y--;
            if(m.count({x,y}))
            {
                if(i-m[{x,y}]<r-l)
                {
                    r=i;
                    l=m[{x,y}];
                }
            }
            m[ {x,y}]=i+1;
        }
        if(l==0)
            cout<<-1<<endl;
        else
            cout<<l+1<<" "<<r+1<<endl;
    }
    return 0;
}

The question yet to be written back, and then slowly back up to title = - =

Published 86 original articles · won praise 0 · Views 1507

Guess you like

Origin blog.csdn.net/qq_43811879/article/details/104215435