[2016-04-09] [Codeforces] [660] C [Hard Process]

Source: Internet
Author: User

    • Time: 2016-04-09-23:59:40 Saturday
    • Title Number: [2016-04-09][codeforces][660][c][hard Process]
    • Title: Given a sequence of 0 1, the maximum number of K 0 is changed to 1, the longest 1 substring is how long,
    • Analysis:
      • Two-point answer
        • Check (): Enumerates substrings of mid and determines whether the number of 0 inside is less than or equal to 1,
  
 
  1. #include<cstdio>
  2. using namespace std;
  3. const int maxn = 3*1E5 + 10;
  4. int a[maxn],b[maxn],n,k;
  5. int check(int x){
  6. for(int i = x ; i <= n ; ++i){
  7. if(b[i] - b[i - x] + k >= x) return 1;
  8. }
  9. return 0;
  10. }
  11. void print(int x){
  12. int flg = 0;
  13. for ( int i = x I <= n ++ i ) {
  14. if ( b [ i ] - b [ i - x + K >= x ) {
  15. for ( int J = i - x + 1 ; j <= I ++ j ) {
  16. a[j] = 1;flg = 1;
  17. }
  18. }
  19. if(flg) break;
  20. }
  21. for(int i = 1;i <= n ; ++i) printf("%d ",a[i]);
  22. }
  23. int main(){
  24. scanf("%d%d",&n,&k);
  25. for(int i = 1 ; i <= n ; ++i){
  26. scanf("%d",a+i);
  27. b[i] = b[i - 1] + a[i];
  28. }
  29. int l = 0,r = n + 1,mid,res;
  30. while(r >= l){
  31. mid = (l + r)>>1;
  32. if(check(mid)){
  33. l = mid + 1;
  34. res = mid;
  35. }
  36. else r = mid - 1;
  37. }
  38. printf("%d\n",res);
  39. print(res);
  40. return 0;
  41. }


From for notes (Wiz)

[2016-04-09] [Codeforces] [660] C [Hard Process]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.