zoukankan      html  css  js  c++  java
  • [差分] [POJ] 3276 Face The Right Way

    数组开太大

    memset超时好几发

    N方枚举+前缀标记

    一顿操作

    /*
        Zeolim - An AC a day keeps the bug away
    */
    
    //pragma GCC optimize(2)
    #include <cstdio>
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <map>
    #include <ctime>
    #include <vector>
    #include <fstream>
    #include <list>
    #include <iomanip>
    #include <numeric>
    using namespace std;
    typedef long long ll;
    
    const int MAXN = 5e3 + 10;
    
    int arr[MAXN];
    
    int mark[MAXN] = {0};
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);     cout.tie(0);
        //freopen("D://test.in", "r", stdin);
        //freopen("D://test.out", "w", stdout);
        
        int n;
    
        char t;
    
        scanf("%d", &n);
    	
    	getchar();
    	
        for(int i = 1; i <= n; i++)
        {
            scanf("%c",&t);
            getchar();
            arr[i] = (t == 'B');
        }
    
        int ans = 0x3f3f3f3f, step = 0;
    	
    //	for(int i = 0; i <= n; i++)
    //	{
    //		cout<<arr[i]<<' ';
    //	}
        for(int i = 1; i <= n; i++)
        {
        	memset(mark, 0, sizeof(mark));
    		 
            int sum = 0, tim = 0;
    
            for(int j = 1; j <= n; j++)
            {
                sum += mark[j];
    
                if(arr[j] + sum % 2 == 1)
                {
                    mark[j] = 1;
                    sum += mark[j];
    
                    if(j + i > n + 1)
                        goto l1;
    
                    mark[j + i] = -1;
    
                    tim++;
                }
            }
            if(tim < ans)
            {
            	ans = tim, step = i;
    		}
    
            l1:
            	
            continue;
    
        }
    
        cout<<step<<' '<<ans<<endl;
    
        return 0;
    }
    
  • 相关阅读:
    Java 8 forEach简单例子
    Intellij IDEA 使用
    java中的sleep()和wait()的区别
    MySQL问答整理
    java 正则例子
    如何在两个线程之间共享数据
    蜻蜓FM涉嫌诈骗投资人和广告主源代码剖析
    玩DNF开启NVIDIA独显的方法
    WSAEventSelect模型编程 详解
    签名时加密失败 --“对程序集签名时出错
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270412.html
Copyright © 2011-2022 走看看