###### Toy Code Plant

The quick brown fox jumps over the lazy dog.

###### Problem 99 Broken Necklace

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int findforward(vector<char>, int, int);
int findbackward(vector<char>, int, int);

int main(){
int n,         // number of beads
maxlength; // biggest number of beads can be accumulated

vector<char> necklace;

fin>>n;

for(int i = 0; i < n; ++i){
}

maxlength = 2;
for(int i = 0; i < n; ++i){
int mylength = findforward(necklace,i,n) +
findbackward(necklace,i-1,n);

// update maxlength.
if(mylength > maxlength) maxlength = mylength;
if(maxlength > n){
maxlength = n;
break;
}
}

fout<<maxlength<<endl;
}

int findforward(vector<char> necklace, int pos, int size){
int length = 1;
int i = (pos + 1) % size;

while(necklace[i] == 'w'){
length++;
i = (i + 1) % size;
if(length == size) return length;
}
}

(necklace[i] == 'w')      ||
length++;
i = (i + 1) % size;
if(length == size) break;
}
return length;
}
int findbackward(vector<char> necklace, int pos, int size){
char currbead,  // start point's color
int length = 1;
int i;

if(pos < 0){         // count from last bead
i = size - 2;
}else if(pos == 0){  // count from first bead
i = size - 1;
}else {              // normal
i = pos - 1;
}

while(necklace[i] == 'w'){
length++;
i--;
if(i < 0) i = size - 1;
if(length == size) return length;
}
}else

(necklace[i] == 'w')      ||
length++;
i--;
if(i < 0) i = size - 1;
if(length == size) break;
}
return length;
}

#### USACO 1.1 Broken Necklace(USACO官方)

2014-11-18 16:18:48

#### Broken Necklace（参考解析）

2012年10月10日 1KB 下载

#### |洛谷|模拟|P1203 [USACO1.1]坏掉的项链Broken Necklace

2016-10-03 14:56:00

#### usaco 1.1.4 Broken Necklace 一道题可以犯多少脑残

2012-02-12 16:50:55

2012年10月21日 15KB 下载

#### USACO1.1.4 Broken Necklace 破碎的项链

2013-11-25 15:58:40

#### [usaco]Broken Necklace题解

2017-05-21 16:07:34

#### [P1203]坏掉的项链

2017-03-14 18:39:29

#### [USACO1.1]坏掉的项链Broken Necklace 题解

2018-02-18 22:54:23

#### [USACO1.1.4]坏掉的项链Broken Necklace

2016-07-28 21:40:59

## 不良信息举报

Problem 99 Broken Necklace