zoukankan      html  css  js  c++  java
  • USACO Section1.1PROB Broken Necklace

    有点麻烦的一道模拟(官方题解好像有复杂度为$O(n)$DP的姿势?,感觉好烦,以后再细看~

    在一些细节上调试了很久很久,囧RZ

    /*
    ID: jusonal1
    PROG: beads
    LANG: C++
    */
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <cstdio>
    #include <algorithm>
    #include <map>
    #include <cstring>
    using namespace std;
    char beads[1000];
    int n;
    int judge(int i) {
        if(i < 1) return n;
        else if(i > n) return 1;
        else return i;
    }
    int find_(int i) {
        int left = judge(i);
        int right = judge(i+1);
        int s_left = judge(i);
        int s_right = judge(i+1);
        int Left = judge(i);
        int Right = judge(i+1);
        int MAX = 0;
        while(beads[left] == beads[s_left]||beads[left] == 'w') {
            ++MAX;
            if(beads[s_left] == 'w') s_left = judge(--s_left);
            left = judge(--left);
            if(left == Right) return MAX+1;
        }
    
        while(beads[right] == beads[s_right]||beads[right] == 'w') {
            ++MAX;
            if(beads[s_right] == 'w') s_right = judge(++s_right);
            right = judge(++right);
            if(left == right) return MAX+1;
        }
        return MAX;
    }
    int main () {
        freopen("beads.in","r",stdin);
        freopen("beads.out","w",stdout);
        scanf("%d",&n);
        for(int i = 1;i <= n;++i) scanf(" %c",&beads[i]);
        int ans = 0;
        for(int i = 1;i <= n;++i) {
            ans = max(ans,find_(i));
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    How to Get Started With AIOps
    第六部分 实现细节
    第一部分 概览
    第五部分 软件架构
    vs2010 sqlite guid 问题
    cordova(phonegap)+qjm 一统天下
    jQuery调用WebServices总是出错问题解决
    phonegap中http链接自动调用本地浏览器解决办法
    MSSQL省市数据库
    博客的第一篇
  • 原文地址:https://www.cnblogs.com/jusonalien/p/4061008.html
Copyright © 2011-2022 走看看