broken necklaces破碎的项链
来源:互联网 发布:启信宝的数据可信度 编辑:程序博客网 时间:2024/04/28 12:22
/*
ID: cjh12851
LANG: C++
TASK: beads
*/
#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
using namespace std;
int i,j,k,a,b,c,n,maxx=0;
int x,x1,x2,T1=1,T2=1,l1,l2;
string s;
char d;
int main()
{
freopen("beads.in","r",stdin);
freopen("beads.out","w",stdout);//格式
cin>>n;
cin>>s;
s=s+s;
a=1;b=0;d=s[0];
for(i=1;i<2*n;i++ ){
if(s[i]==d||s[i]=='w')a++;//若s[0]=w,亦可行
else{
d=s[i];
if(a+b>maxx)maxx=a+b;
b=a;
a=1;
for(j=i-1;s[j]=='w';j--){
a++;b--;//往回查找,并保证w属于后一串珠子;
}
}
}
if(maxx==0||maxx>n)maxx=n;//若无断点,则maxx=0;
cout<<maxx<<endl;
return 0;
}
ID: cjh12851
LANG: C++
TASK: beads
*/
#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
using namespace std;
int i,j,k,a,b,c,n,maxx=0;
int x,x1,x2,T1=1,T2=1,l1,l2;
string s;
char d;
int main()
{
freopen("beads.in","r",stdin);
freopen("beads.out","w",stdout);//格式
cin>>n;
cin>>s;
s=s+s;
a=1;b=0;d=s[0];
for(i=1;i<2*n;i++ ){
if(s[i]==d||s[i]=='w')a++;//若s[0]=w,亦可行
else{
d=s[i];
if(a+b>maxx)maxx=a+b;
b=a;
a=1;
for(j=i-1;s[j]=='w';j--){
a++;b--;//往回查找,并保证w属于后一串珠子;
}
}
}
if(maxx==0||maxx>n)maxx=n;//若无断点,则maxx=0;
cout<<maxx<<endl;
return 0;
}
-----------------------------------------------------------------本题的方法为断点枚举。
0 0
- broken necklaces破碎的项链
- Broken Necklace破碎的项链
- Broken Necklace破碎的项链
- usaco1.1.4 Broken Necklace破碎的项链
- USACO1.1.4 Broken Necklace(破碎的项链)
- USACO1.1.4 Broken Necklace 破碎的项链
- Broken Necklace-----破碎的项链----USACO---C1S1
- Usaco 1.1.4 破碎的项链(Broken Necklace)
- 【USACO1.1_4】★Broken Necklace 破碎的项链
- 【USACO题库】1.1.4 Broken Necklace破碎的项链
- 【USACO题库】1.1.4 Broken Necklace破碎的项链
- 【USACO题库】1.1.4 Broken Necklace破碎的项链
- 【模拟】【RQNOJ】破碎的项链
- USACO Section1.2破碎的项链
- USACO 1.1 破碎的项链
- USACO 1.1 破碎的项链(模拟)
- Broken Necklace 坏掉的项链
- [USACO1.1.4]坏掉的项链Broken Necklace
- 查找——AVL
- 字典序问题
- java开发C语言解释器:函数递归调用时的环境保护
- gradle的使用,在ide的设置
- 2017 终点亦是起点
- broken necklaces破碎的项链
- HDU 1001【Sum Problem】
- redis 的惊群处理和分布式锁的应用例子
- TensorFlow 一个线程回归的例子
- cloudera-scm-server dead but pid file exists 问题分析和解决
- shiro权限配置注解的时候发现 Exception sending context initialized event to listener instance of class org
- 有趣的网站
- 摄像头 RTSP 以及远程管理
- Python爬虫包 BeautifulSoup 学习(十) 各种html解析器的比较及使用