「日常训练」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;
}
「日常训练」Divisibility by Eight(Codeforces Round 306 Div.2 C)的更多相关文章
- 「日常训练」Regular Bridge(Codeforces Round 306 Div.2 D)
题意与分析 图论基础+思维题. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back #defi ...
- 「日常训练」Two Substrings(Codeforces Round 306 Div.2 A)
题意与分析 一道非常坑的水题.分析醒了补. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back ...
- 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)
题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...
- 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)
题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...
- 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)
题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...
- 「日常训练」Ice Cave(Codeforces Round 301 Div.2 C)
题意与分析(CodeForces 540C) 这题坑惨了我....我和一道经典的bfs题混淆了,这题比那题简单. 那题大概是这样的,一个冰塔,第一次踩某块会碎,第二次踩碎的会掉落.然后求可行解. 但是 ...
- 「日常训练」School Marks(Codeforces Round 301 Div.2 B)
题意与分析(CodeForces 540B) 题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲:第二分数的中位数(科目数 ...
- 「日常训练」The Intriguing Obsession(CodeForces Round #439 Div.2 C)
2018年11月30日更新,补充了一些思考. 题意(CodeForces 869C) 三堆点,每堆一种颜色:连接的要求是同色不能相邻或距离必须至少3.问对整个图有几种连接方法,对一个数取模. 解析 要 ...
- 「专题训练」Hard problem(Codeforces Round #367 Div. 2 C)
题意与分析 题意:给出\(n\)个字符串,可以反转任意串,反转每个串都有其对应的花费\(c_i\).经过操作后是否能满足字符串\(\forall i \in [1,n] \text{且} i \in ...
随机推荐
- Anaconda安装与常用命令及方法(深度学习入门1)
Anaconda是一个软件发行版,它附带了 conda.Python 和 150 多个科学包及其依赖项. 安装Anaconda Anaconda分为Linux.Windows.Mac等版本,去 htt ...
- Server.xml解析
来源 本文整理自 <Tomcat内核设计剖析>.<Tomcat结构解析> 加上自己的理解.源码来自 Tomcat8.5 版本 <Server port="800 ...
- hdu 1021 Fibonacci Again(变形的斐波那契)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Ot ...
- 微信小程序获取手机信息
wx.getSystemInfo({ success: function (res) { console.log(res.model)//手机型号 console.log(res.pixelRatio ...
- Oracle 触发器(一)
1)触发器是一种特殊的存储过程,触发器一般由事件触发并且不能接受参数,存储器由语句块去调用:触发器是当某个事件发生时自动地隐式运行. 2)触发器分类: 1.DML触发器: 创建在表上,由DML事件引发 ...
- MySQL正则表达式的问题
原本以为 正则表达式里面的特殊\d匹配数字放到sql语句里面也是适用的,没想到一直不匹配.但是放到编程语言java或者js里面又匹配.看了一下原来sql对正则的支持没有那么全面.一定要用[0-9]代表 ...
- 【若泽大数据实战第二天】Linux命令基础
Linux基本命令: 查看IP: ifconfig 或者 hostname -i(需要配置文件之后才可以使用) ipconfig(Windows) 关闭防火墙: Service iptables st ...
- SQL Server 2012 - 多表连接查询
-- 交叉连接产生笛卡尔值 (X*Y) SELECT * FROM Student cross Join dbo.ClassInfo --另外一种写法 SELECT * FROM Student , ...
- ueditor 富文本编辑器 Uncaught TypeError: Cannot set property 'innerHTML' of undefined问题
ueditor.addListener("ready", function () { ueditor.setContent(‘内容'); });
- 使用NPOI将数据导出Excel
NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); NPOI.SS.UserModel.IS ...