Regionals 2014 >> Latin America
2015-09-03 11:43
218 查看
题意:找出多少个子串满足以下条件:是数字且能被3整除
思路:本状态根据前一状态退出,本状态的这个数字取余后加上原来状态会变成下一个状态。
#include <iostream> #include <cstdio> #include <cstring> #include <map> #include <cmath> #include <vector> using namespace std; typedef long long ll; #define MAX 20005 #define PI acos(-1.0) bool isdigit(char c){ if(c>='0' && c<='9') return true; return false; } char str[1000005]; int f[1000005]; int main(){ while(~scanf("%s", str)){ int len = strlen(str); ll ans = 0; int then = -1; int flag = 0; ll t1 = 0,t2 = 0,t3 = 0; for(int i = 0;i < len;i++){ if(isdigit(str[i])){ int t = (str[i]-'0')%3; ll tt1 = 0,tt2 = 0,tt3 = 0; if(t == 0){ // t1 ++; tt1 = t1,tt2 = t2,tt3 = t3; tt1 ++; //noice } else if(t == 1){ // t2 ++; tt1 = t3,tt2 = t1,tt3 = t2; tt2 ++; //noice } else{ // t3 ++; tt1 = t2,tt2 = t3,tt3 = t1; tt3 ++; //noice } ans += tt1; t1 = tt1,t2 = tt2,t3 = tt3; } else{ t1 = t2 = t3 = 0; } } printf("%lld\n", ans); } return 0; } /*4 3 BWWWWWBWBWBWWBWBWBWWWB 6 2 BWWBWBWWWBWBBBBW */
相关文章推荐
- JS-案例-节点交换
- poj 1719最大二分匹配hungary算法
- 设置你的开发环境(Eclipse中,IntelliJ IDEA的,NetBeans的)
- 下个Win10 Mobile预览版将修复10512系统众多Bug 包括网络共享
- 用图片数字显示对应的数目
- BZOJ 1263: [SCOI2006]整数划分( 高精度 )
- Java就业指导
- 第10章 无监督学习(2)
- SQL Server 事件通知(Event notifications)
- ultra edit ftp帐号导入导出方法
- 贪婪算法
- AOP——引言
- iPhone开发之UITableView的小试牛刀 利用MVC模式从plist文件读取数据并字典转模型的格式实现
- Python学习----函数式编程
- 工厂模式/抽象工厂模式
- Python2.7生成大连交通大学IPTV播放列表
- Eclipse中web项目部署至Tomcat步骤
- django 1.8 官方文档翻译: 2-4-3 模式编辑器
- 使用MC.EXE定义错误码
- h5 audio 和 video