| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:帮忙找错的测试数据!我是在是找不出来。感觉不应该WA……In Reply To:帮忙找错的测试数据!我是在是找不出来。感觉不应该WA…… Posted by:0406340341 at 2007-12-30 17:18:49 > #include <iostream>
>
> using namespace std;
>
> #define N 1000005
>
> int next_num[N], next[N], num[N], end[N];
> char color[N];
>
> int main()
> {
> scanf("%s",color);
>
> int len = strlen( color );
> int last=0, all =0, start=0;
>
> for(int i=0;i<len;i++)
> {
> next[i] = i+1;
> if(color[last] == color[i])
> {
>
> }
> else
> {
> next_num[last] = i;
> end[last] = i-1;
> num[last] = i-last;
> last = i;
> all ++;
> }
> }
> next_num[last] = len;
> end[last] = len - 1;
> num[last] = len-last;
> all++;
>
> while(1)
> {
> int max = start;
> last = start;
> for(int i=start;i<len;i=next_num[i])
> {
> if(num[i] > num[max])
> {
> last = max;
> max = i;
> }
> }
>
> if(num[max] == 1) break;
> else
> {
> printf("%c",color[max]);
> for(int i=max,j=0;j<num[max];i=next[i],j++)
> {
> printf(" %d",i+1);
> }
> printf("\n");
> }
> all--;
>
> int ne = next_num[max];
> if(max == start)
> {
> start = ne;
> }
> else if(color[last] == color[ne])
> {
> next[ end[last] ] = ne;
> num[last] += num[ne];
> end[last] = end[ne];
> next_num[last] = next_num[ne];
> all--;
> }
> else
> {
> next[ end[last] ] = ne;
> next_num[last] = ne;
> }
>
> if(start == len) break;
> }
>
>
> return 0;
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator