您的位置:首页 > 其它

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
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: