zoukankan      html  css  js  c++  java
  • 「日常训练」Divisibility by Eight(Codeforces Round 306 Div.2 C)

    题意与分析

    极简单的数论+思维题。

    代码

    #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;
    }
    
    如非注明,原创内容遵循GFDLv1.3发布;其中的代码遵循GPLv3发布。
  • 相关阅读:
    hdoj--2098--分拆素数和(枚举)
    hdoj--3594--Cactus(tarjan)
    hdoj--1251--统计难题(字典树)
    hdoj--2534--Score(gcd)
    nyoj--1185--最大最小值(线段树)
    hdoj--1166--敌兵布阵(线段树)
    hdoj--1754--I Hate It(线段树)
    poj--2234--Matches Game(尼姆博弈)
    lightoj--1005--Rooks(组合数)
    SPOJ
  • 原文地址:https://www.cnblogs.com/samhx/p/cfr306d2c.html
Copyright © 2011-2022 走看看