GYM Amman 17 J. Spilt the String 模拟,枚举
来源:互联网 发布:淘宝订单编号查询系统 编辑:程序博客网 时间:2024/06/03 19:46
题意:给出字符串s 包含空格.问是否能把s分成若干个区间.满足每个字符串只会落在某个区间,并且每个区间长度都相同.|s|<=1e5.
因为一个字符串不会落在多个区间上 所有分割的位置只能为空格.
因为一个字符串不会落在多个区间上 所有分割的位置只能为空格.
枚举区间长度x,判断分割点是否为空格即可O(nlogn).
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e5+5,mod=1e9+7;char s[N];//3 4 10 11 7bool solve(){ int len=strlen(s+1); for(int x=2;2*(x-1)<=len;x++)//len =x-1 { bool flag=true; int i=x; while(i<=len) { if(s[i]!=' ') { flag=false; break; } i+=x; } if(flag&&i==len+1) return true; } return false;}int main(){ int T; cin>>T; getchar(); while(T--) { gets(s+1); if(solve()) printf("YES\n"); else printf("NO\n"); } return 0;}
阅读全文
0 0
- GYM Amman 17 J. Spilt the String 模拟,枚举
- GYM Amman 17 G. Super Subarray 暴力,最小公倍数.
- Codeforces Gym 100342J Triatrip Bitset+枚举
- GYM 100883 J.palprime(枚举)
- 【模拟】NEERC15 J Jump (Codeforces GYM 100851)
- GYM 2017 ACM Amman Collegiate Programming Contest
- GYM 100801J Journey to the “The World's Start”
- 2017 ACM Amman Collegiate Programming Contest J
- Gym - 100203J Journeys on the Moscow Underground
- GYM 100247 J. The Best Statement(水~)
- String spilt的使用心得
- 举例说明String.spilt()的用法
- Java中String的spilt
- Codeforces Gym 2015 ACM Amman Collegiate Programming Contest
- CodeForces Gym 100989F Mission in Amman (A)
- CodeForces Gym 100989G Mission in Amman (B)
- Gym 100917 J. Judgement
- Gym-100712J-Candy
- 物理引擎
- Mysql中查找附近人的查询语句
- Spring透过ApplicationListener来触发contextrefreshedevent事件
- jenkins 安装
- 系统上线的步骤
- GYM Amman 17 J. Spilt the String 模拟,枚举
- 虚拟机、系统的使用基础方法,简单的系统命令
- docker中安装hadoop过程及错误解决
- Dubbo背景和简介
- Spring 框架学习(四):AOP
- Git学习总结
- matlab中函数regionprops属性意义
- Git忽略规则及.gitignore规则不生效的解决办法
- <Android> 系统编译删除不必要的Apk