FZU 2041 Checker (Greedy + simulation)

Source: Internet
Author: User

FZU 2041 Checker (Greedy + simulation)

 
This is one of the sets of questions used for the competition in yesterday's team. I thought of the method, but I did not dare to write it .. One is a bit uncertain about the complexity. In case of a large number of groups, it seems like you will kneel down .. In addition, I feel that it is not very easy to implement. I am stuck with two questions in the team, so I plan to wait for another question to come out and write it again. The result is no longer available ..
I wrote about it just now .. The result is over... Really drunk .. Me &...... % ¥ % **...... %
The idea is to enumerate each gap first, and then move the gap to the left to the right in a greedy step. The rest is a small simulation. Then we can find the maximum possible expansion of all gaps.
The Code is as follows:

#include 
  
   #include 
   
    #include #include 
    
     #include
     #include 
      
       #include 
       
        #define LL __int64#define INF 0x3f3f3f3f#define PI acos(-1)#define eqs 1e-15const int mod = 1e9+7 ;using namespace std ;char s[600];int a[600], cnt;struct node { int l, r, x;} fei[600];int main(){ int t, n, m, i, j, flag, lstep, rstep, max1, step, Case=0, mm; scanf(%d,&t); while(t--) { scanf(%d%d,&n,&mm); scanf(%s,s+1); s[0]='1'; s[n+1]='1'; cnt=0; flag=0; max1=0; for(i=0; i<=n+1; i++) { if(s[i]=='1') { if(flag) { flag=0; fei[cnt].r=i; cnt++; } fei[cnt].l=i; fei[cnt].x=0; } else { flag=1; fei[cnt].x++; max1=max(max1,fei[cnt].x); } } for(i=0; i
        
         =0; j--) { if(!a[j]) { lstep=fei[i].l-j; break; } } rstep=INF; for(j=fei[i].r; j<=n+1; j++) { if(!a[j]) { rstep=j-fei[i].r; break; } } step=min(lstep,rstep); if(m
         
        
       
      
    
   
  

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.