USACO 1.1 Broken Necklace_天涯浪子_新浪博客

[报告]

   首先,把环打开——就是str=str+str+str(我的程序在最前面+了个'\0',这是我多年PASCAL与C++混写的习惯),然后从第N+1位到第N+N位,以那位与它前面那个之间的空隙进行枚举。并且向左搜索一次,向右搜索一次。求出要你求的东西,然后和ANS比较,求出最大的就可以拉!

   USACO 1~3 都是些比较简单的题目,我相信。

[程序]


#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream fin ("beads.in");
ofstream fout ("beads.out");
long n;
string str;
long ans;
inline void init()
{
       fin >> n;
       fin >> str;
       str='\0'+str+str+str;
}
inline void calc()
{
       ans=0;
       for (long m=n+1;m<=n+n;m++)
       {
       //    cout << m << endl;
           char x='w';
           long s=0;
           for (long i=m-1;i>=1&&(str[i]=='w'||x=='w'||str[i]==x);i--,s++)
               if (str[i]!='w')
                  x=str[i];
      //     cout << x << " " << s << " | ";
           x='w';
           for (long i=m;i<=n+n+n&&(str[i]=='w'||x=='w'||str[i]==x);i++,s++)
               if (str[i]!='w')
                  x=str[i];
         //  cout << x << " " << s << endl;
           if (s>ans)
           {
              ans=s;
              if (ans>n)
              {
             

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值