Codeforces 1005D:Polycarp and Div 3
题目链接:http://codeforces.com/problemset/problem/1005/D
题意
给出个字符串(全是数字),把这个字符串换分成一些子串,最多能划分多少个能够被3整除的子串(字符串去掉前导零,0能被3整除)
AC代码
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
using namespace std;
char ch[maxn];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
cin>>ch;
int l=strlen(ch);
int ans=0;
int sum=0;
int x=0;
int res;
for(int i=0;i<l;i++)
{
res=(ch[i]-'0')%3;
sum+=res;
x++;
if(res==0||sum%3==0||x==3)
{
ans++;
sum=0;
x=0;
}
}
cout<<ans<<endl;
return 0;
}
Codeforces 1005D:Polycarp and Div 3的更多相关文章
- 『ACM C++』 Codeforces | 1005D - Polycarp and Div 3
今天佛了,魔鬼周一,在线教学,有点小累,但还好,今天AC了一道,每日一道,还好达成目标,还以为今天完不成了,最近任务越来越多,如何高效完成该好好思考一下了~最重要的还是学业的复习和预习. 今日兴趣新闻 ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
随机推荐
- oracle 如何查看当前用户的表空间名称
如何查询当前用户的表空间名称?因为oracle建立索引,需要知道当前用户的表空间,查找了一下资料 --查询语法-- select default_tablespace from dba_users w ...
- valgrind 工具介绍和简单的使用
最近老是遇上各种奇奇怪怪的core dump,不太会分析的情况下看到了这款工具.在这记录分享下. Valgrind 是个开源的工具,功能很多.例如检查内存泄漏工具---memcheck. Valgri ...
- MATLAB统计工具箱 转
D:\Program Files\MATLAB\R2012b\toolbox\stats\stats MATLAB统计工具箱包括概率分布.方差分析.假设检验.分布检验.非参数检验.回归分析.判别分析. ...
- php对于url提交数据的获取办法
$url = Request::getUri();//获取当前的url $arr = parse_url($url); //$arr_query = convertUrlQuery($arr['que ...
- 【原创】QT简单计算器
代码 //main.cpp #include "calculator_111.h" #include <QtWidgets/QApplication> int main ...
- Guns后台管理系统框架(毕业设计神器)
Guns后台管理系统, 基于Spring Boot + Maven构建 + MyBatis + MySql数据库 导入Eclipse即可使用 十分钟即可搞定,做毕业设计的好帮手啊 最终效果图 登陆页 ...
- CString、string、const char*的相互转换
环境:vs2010 1.CString转string //第一种方式: CString str = _T("CSDN"); USES_CONVERSION; std::string ...
- bootstrap 下拉选中查询
<div class="form-group"> <label class="col-lg-3 col-sm-2 control-label" ...
- java基础入门系列1
学java之前先了解下window系统的的一些常识: #常用windows快捷键 ctrl+x:剪切 ctrl+z:撤销 ctrl+A:全选 ctrl+V:黏贴 windows+d:回到桌面 Wind ...
- tensorflow-LSTM-网络输出与多隐层节点
本文从tensorflow的代码层面理解LSTM. 看本文之前,需要先看我的这两篇博客 https://www.cnblogs.com/yanshw/p/10495745.html 谈到网络结构 ht ...