zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 11 C hard process_补题——作为司老大的脑残粉

      司老大当时教了一种姿势枚举连续K个0,说实话当时比赛写这题完全蒙了 纵然后来知道思路还是写了一段时间 真的是。。

    题目大意  n长度的序列,由0 1构成 我们可以改变 k个0为1 求可以得到的最长连续1序列的长度

    既然求连续1 我们贪心连续k个0 枚举端点 左端点0设置为0 右端点0设置为 n+1 中间统计一下 最长长度和改变的0的位置就OK了 

     1 #include<cstdio>
     2 #include<map>
     3 //#include<bits/stdc++.h>
     4 #include<vector>
     5 #include<stack>
     6 #include<iostream>
     7 #include<algorithm>
     8 #include<cstring>
     9 #include<cmath>
    10 #include<queue>
    11 #include<cstdlib>
    12 #include<climits>
    13 #define INF 0x3f3f3f3f
    14 using namespace std;
    15 typedef long long ll;
    16 typedef __int64 int64;
    17 const ll mood=1e9+7;
    18 const int64 Mod=998244353;
    19 const double eps=1e-9;
    20 const int MAXN=100010;
    21 const double PI=acos(-1.0);
    22 inline void rl(ll&num){
    23     num=0;ll f=1;char ch=getchar();
    24     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    25     while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
    26     num*=f;
    27 }
    28 inline void ri(int &num){
    29     num=0;int f=1;char ch=getchar();
    30     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    31     while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
    32     num*=f;
    33 }
    34 int getnum()//相邻的个位整数输入 如想分别保存1234 输入连续的1234 a[i]=getnum();就可以实现
    35 {
    36     char ch=getchar();
    37     while((ch<'0' || ch>'9') && ch!='-')
    38         ch=getchar();
    39     return (ch-'0');
    40 }
    41 inline void out(int x){ if(x<0) {putchar('-');  x*=-1;}if(x>9) out(x/10);  putchar(x%10+'0'); }
    42 int a[300020],b[300020];
    43 int main()
    44 {
    45     int n,k;
    46     ri(n),ri(k);
    47     int len=0,tem;
    48     for(int i=1;i<=n;i++)
    49     {
    50         ri(b[i]);
    51         if(!b[i]) a[++len]=i;
    52     }
    53     if(k>=len){
    54         out(n);putchar('
    ');
    55         for(int i=1;i<=n;i++)
    56         {
    57             putchar('1');
    58             if(i!=n)putchar(' ');
    59         }
    60         putchar('
    ');
    61     }
    62     else{
    63         a[0]=0;a[len+1]=n+1;
    64         int mx=-1,l,r;
    65         for(int i=1;i-1+k<=len;i++)
    66         {
    67             if(mx<a[i+k]-a[i-1]-1)
    68             {
    69                 mx=a[i+k]-a[i-1]-1;
    70                 l=a[i-1]+1;
    71                 r=a[i+k]-1;
    72             }
    73         }
    74         out(mx);putchar('
    ');
    75         for(int i=1;i<=n;i++)
    76         {
    77             if(i>=l&&i<=r)putchar('1');
    78             else out(b[i]);
    79             if(i!=n)putchar(' ');
    80         }
    81     }
    82     return 0;
    83 }
    要有思想

    至于廷伟菊苣说的dp和线段树姿势还不会。。。

  • 相关阅读:
    如何阅读修改代码
    C C++ TDD单元测试非常好的书
    应用代理 socket TCP协议 的资料
    闲聊桌面应用开发[Win16->Win32->ATL/WTL/MFC->WinForm->WPF/Silverlight/WinRT]
    MySQL sharding的几个参考地址
    ubuntu环境变量
    Angular JS | Closure | Google Web Toolkit | Dart | Polymer 概要汇集
    Linux下的应用程序性能分析 总结
    ubuntu处理中文时设置locale
    Tomcat https自制证书和浏览器配置
  • 原文地址:https://www.cnblogs.com/Geek-xiyang/p/5397583.html
Copyright © 2011-2022 走看看