XJTU Summer Holiday Test 1(Divisibility by Eight-8的倍数)
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
cid=82382#status//C/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); background-color:rgb(227,228,248); color:rgb(85,85,85)">Status
Description
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8.
After the removing, it is forbidden to rearrange the digits.
If a solution exists, you should print it.
Input
The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes
and its length doesn't exceed 100 digits.
Output
Print "NO" (without quotes), if there is no such way to remove some digits from number n.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible
by 8.
If there are multiple possible answers, you may print any of them.
Sample Input
3454
YES
344
10
YES
0
111111
NO
8*125=1000 故一个数是8的倍数当且仅当它末尾3个数是8的倍数
所以答案最多有3位,暴力就可以
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
char s[MAXN];
int main()
{
// freopen("I.in","r",stdin);
// freopen(".out","w",stdout); scanf("%s",s);
char *pch=strstr(s,"AB");
if (pch!=NULL&&strstr(pch+2,"BA")!=NULL)
{
cout<<"YES"<<endl;
return 0;
}
pch=strstr(s,"BA");
if (pch!=NULL&&strstr(pch+2,"AB")!=NULL)
{
cout<<"YES"<<endl;
return 0;
}
cout<<"NO"<<endl; return 0;
}
XJTU Summer Holiday Test 1(Divisibility by Eight-8的倍数)的更多相关文章
- XJTU Summer Holiday Test 1(Brackets in Implications-构造)
B - Brackets in Implications Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- 【UOJ #29】【IOI 2014】holiday
http://uoj.ac/problem/29 cdq四次处理出一直向左, 一直向右, 向左后回到起点, 向右后回到起点的dp数组,最后统计答案. 举例:\(fi\)表示一直向右走i天能参观的最多景 ...
- cf306 C. Divisibility by Eight(数学推导)
C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 水题 ZOJ 3876 May Day Holiday
题目传送门 /* 水题:已知1928年1月1日是星期日,若是闰年加1,总天数对7取余判断就好了: */ #include <cstdio> #include <iostream> ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...
- 周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏
Clique in the Divisibility Graph time limit per test1 second memory limit per test256 megabytes inpu ...
- 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏
May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...
- HDU 4118 Holiday's Accommodation
Holiday's Accommodation Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 200000/200000 K (Jav ...
- Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
随机推荐
- 用正则表达式模仿Mustache插件的功能
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- IMAGE_OPTIONAL_HEADER32 结构作用
IMAGE_OPTIONAL_HEADER32 结构作用 接 着我们来谈谈 IMAGE_OPTIONAL_HEADER 结构,正如名字的意思,这是一个可选映像头,是一个可选的结构,但是呢,实际上上节课 ...
- arduino ide的串口权限解决
刚刚到手一个Arduino uno R3的板子,windows下arduino IDE的串口正常使用,linux下却出现权限问题,解决方案如下:(以下操作使用超级用户) 1.查看设备所在的组ls -l ...
- python 锁 多进程
参考: http://www.cnblogs.com/huxi/archive/2010/06/26/1765808.html http://linhs.blog.51cto.com/370259/1 ...
- Math.ceil()、floor()、round()
ceil():向上取整,>=某个小数的最小整数,即15.3取16.返回double类型 如果参数小于0且大于-1.0,结果为 -0. floor():向下取整,<=某个小数的最大整数,即1 ...
- 如何证明一个数的数根(digital root)就是它对9的余数?
数根就是不断地求这个数的各位数之和,直到求到个位数为止.所以数根一定和该数模9同余,但是数根又是大于零小于10的,所以数根模9的余数就是它本身,也就是说该数模9之后余数就是数根. 证明: 假设有一个n ...
- codevs——3111 CYD啃骨头(背包)
裸的01背包 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description CYD吃饭时有N个骨头可以啃,但CYD要午睡了 ...
- SVN源码服务器搭建-详细教程
一.引言 笔者曾经试图在网上搜索一篇关于SVN源代码服务器搭建方面的中文技术文章,可惜,所找到的,要么是不完整,要么就是对笔者没什么帮助的文章,TortoiseSvn的帮助文档固然强大,但因为是英文, ...
- GLSL纹理贴图 【转】
转载:http://blog.csdn.net/hgl868/article/details/7872466 简单的纹理贴图(Simple Texture) 为了在GLSL中应用纹理,我们需要访问每个 ...
- C++中的void类型
Technorati 标签: void,指针 1.1. void类型 void类型其实是一种用于语法性的类型,而不是数据类型,主要用于作为函数的参数或返回值,或者定义void指针,表示一种未知类型. ...