「日常訓練」Divisibility by Eight(Codeforces Round 306 Div.2 C)

來源:互聯網
上載者:User

標籤:string   first   back   bool   class   代碼   quic   mem   fir   

題意與分析

極簡單的數論+思維題。

代碼
#include <bits/stdc++.h>#define MP make_pair#define PB emplace_back#define fi first#define se second#define ZERO(x) memset((x), 0, sizeof(x))#define ALL(x) (x).begin(),(x).end()#define rep(i, a, b) for (repType i = (a); i <= (b); ++i)#define per(i, a, b) for (repType i = (a); i >= (b); --i)#define QUICKIO                      ios::sync_with_stdio(false);     cin.tie(0);                      cout.tie(0);using namespace std;using ll=long long;using repType=int;bool judge(int x){    if(x%8==0)    {        cout<<"YES"<<endl<<x<<endl;        return true;    }    return false;}bool judge(int x,int y){    if(judge(x) || judge(y) || judge(x*10+y)) return true;    return false;}int main(){    string str; cin>>str;    if(str.length()<=2)    {        if(str.length()==1)        {            if((str[0]-‘0‘)%8) cout<<"NO"<<endl;            else            {                cout<<"YES"<<endl<<str<<endl;            }            return 0;        }        else        {            if((str[0]-‘0‘)%8==0)            {                cout<<"YES"<<endl<<str[0]<<endl;                return 0;            }            else if((str[1]-‘0‘)%8==0)            {                cout<<"YES"<<endl<<str[1]<<endl;                return 0;            }            else if(((str[1]-‘0‘)*10+str[0]-‘0‘)%8==0)            {                cout<<"YES"<<endl<<str<<endl;                return 0;            }            cout<<"NO"<<endl;            return 0;        }    }    rep(i,0,str.length()-3)    {        int x=str[i]-‘0‘;         if(judge(x)) return 0;        rep(j,i+1,str.length()-2)        {            int y=str[j]-‘0‘;            if(judge(y) || judge(x,y)) return 0;            rep(k,j+1,str.length()-1)            {                int z=str[k]-‘0‘;                if(judge(z) || judge(x,z) || judge(y,z)) return 0;                if(z%2) continue;                //cout<<x<<" "<<y<<" "<<z<<endl;                //cout<<(!(x%2))<<" "<<(y*10+z)%8<<((!(x%2)) && (y*10+z)%8==4)<<endl;                if((!(x%2) && (y*10+z)%8==0) || (x%2 && (y*10+z)%8==4))                {                    cout<<"YES"<<endl;                    //cout<<i<<" "<<j<<" "<<k<<endl;                    rep(p,0,str.length()-1)                    {                        //cout<<"("<<p<<") ";                        if(p<i || p==i || p==j || p==k) cout<<str[p];                    }                    cout<<endl;                    return 0;                }            }        }    }    cout<<"NO"<<endl;    return 0;}

「日常訓練」Divisibility by Eight(Codeforces Round 306 Div.2 C)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.