Last active
October 25, 2015 08:33
-
-
Save panda2134/ee5cc13ef00a95ae3904 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LANG:C++11 | |
PROG:beads | |
USER:smallpa2 | |
*/ | |
#ifdef DEBUG | |
#include<iostream> | |
#else | |
#include<fstream> | |
#endif | |
#include<cstring> | |
using namespace std; | |
int len,maxn; | |
char beads[1000],btmp[1000]; | |
int countF(char color,char* start,char* end); | |
int countB(char color,char* start,char* end); | |
int main(){ | |
#ifndef DEBUG | |
ifstream cin("beads.in"); | |
ofstream cout("beads.out"); | |
#endif | |
cin>>len; | |
cin>>beads; | |
memcpy(beads+len,beads,len); | |
//memcpy(beads+2*len,beads,len); | |
for(int i=0;i<len;i++){ | |
for(int j=i+1;j<i+len;j++){ | |
memcpy(btmp,beads,len*3); | |
int cfr=countF('r',btmp+i,btmp+j); | |
int cbr=countB('r',btmp+j,btmp+i); | |
memcpy(btmp,beads,len*3); | |
int cfb=countF('b',btmp+i,btmp+j); | |
int cbb=countB('b',btmp+j,btmp+i); | |
memcpy(btmp,beads,len*3); | |
int end1=max(cfr,cfb); | |
int end2=max(cbr,cbb); | |
if(end1+end2==12) cout<<"max "<<i<<','<<j<<endl; | |
maxn=max(maxn,end1+end2); | |
} | |
} | |
cout<<maxn<<endl; | |
} | |
int countF(char color,char* start,char* end){ | |
int num=0; | |
for(char* ptr=start;ptr<=end;ptr++){ | |
if(*ptr==color || *ptr=='w'){ | |
num++; | |
*ptr='d'; | |
}else | |
break; | |
} | |
return num; | |
} | |
int countB(char color,char* start,char* end){ | |
int num=0; | |
for(char* ptr=start;ptr>=end;ptr--){ | |
if(*ptr==color || *ptr=='w'){ | |
num++; | |
*ptr='d'; | |
} | |
else | |
break; | |
} | |
return num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
program to the problem "broken necklace" on usaco
debugging