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