<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Codeforces Round #598 (Div. 3) D. Binary String Minimizing 貪心

      D. Binary String Minimizing

      You are given a binary string of length n (i.?e. a string consisting of n characters '0' and '1').

      In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than k moves? It is possible that you do not perform any moves at all.

      Note that you can swap the same pair of adjacent characters with indices i and i+1 arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.

      You have to answer q independent test cases.

      Input

      The first line of the input contains one integer q (1≤q≤104) — the number of test cases.

      The first line of the test case contains two integers n and k (1≤n≤106,1≤k≤n2) — the length of the string and the number of moves you can perform.

      The second line of the test case contains one string consisting of n characters '0' and '1'.

      It is guaranteed that the sum of n over all test cases does not exceed 106 (∑n≤106).

      Output

      For each test case, print the answer on it: the lexicographically minimum possible string of length n you can obtain from the given one if you can perform no more than k moves.

      Example

      input
      3
      8 5
      11011010
      7 9
      1111100
      7 11
      1111100
      output
      01011110
      0101111
      0011111

      Note

      In the first example, you can change the string as follows: 110–––11010→10–––111010→011110–––10→01110–––110→0110–––1110→01011110.

      In the third example, there are enough operations to make the string sorted.

      題意

      現在有t組數據,每組數據給你n和k;表示二進制的長度和操作次數。
      每次操作你可以選擇一個數和他相鄰的位置進行交換,在不超過k次的操作次數情況下,使得這個字符串變得最小。

      題解

      貪心,每次操作最小的數,使得他盡可能的放在前面;由于里面只有0和1,其實就是操作0,把0盡可能的往前面放。

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      
      int n;
      long long k;
      string s;
      vector<int>p;
      void solve(){
      	scanf("%d%lld",&n,&k);
      	cin>>s;
      	p.clear();
      	for(int i=0;i<s.size();i++){
      		if(s[i]=='0'){
      			p.push_back(i);
      		}
      	}
      	int la=-1;
      	for(int i=0;i<p.size();i++){
      	   // cout<<"before "<<p[i]<<" "<<k<<endl;
      		if(k>p[i]-la-1){
      			int cost=p[i]-la-1;
      			k-=cost;
      			p[i]=la+1;
      			la=p[i];
      		}else{
      			p[i]-=k;
      			break;
      		}
      		//cout<<"aft "<<p[i]<<" "<<k<<endl;
      	}
      	vector<int>o(s.size(),1);
      	for(int i=0;i<p.size();i++){
      		o[p[i]]=0;
      	}
      	for(int i=0;i<o.size();i++){
      		cout<<o[i];
      	}
      	cout<<endl;
      }
      int main(){
      	int t;
      	scanf("%d",&t);
      	while(t--)solve();
      }
      
      posted @ 2019-11-05 15:49  qscqesze  閱讀(309)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲精品国产av成拍色拍个| 老司机午夜精品视频资源| 精品无码国产不卡在线观看| 恩平市| 国内精品久久久久影院日本| 国产亚洲亚洲国产一二区| 亚洲中文字幕人成影院| 中文字幕无码视频手机免费看| 亚洲欧美日韩愉拍自拍美利坚| 久青草视频在线免费观看| 久久精品国产亚洲夜色av| 久久国产精99精产国高潮| 亚洲人成网站观看在线观看 | julia无码中文字幕一区| 日韩人妻少妇一区二区三区| 亚洲第一人伊伊人色综合| 亚洲综合色成在线播放| 中文字幕精品亚洲字幕成| 五月天丁香婷婷亚洲欧洲国产| 综合偷自拍亚洲乱中文字幕| 精品人妻av区乱码| 欧洲无码一区二区三区在线观看| 丁香五月亚洲综合在线国内自拍| 五月丁香六月综合缴情在线 | 亚洲国产成人精品女久久| 私人毛片免费高清影视院| 亚洲熟女国产熟女二区三区| 色视频不卡一区二区三区| 日韩精品久久久肉伦网站| 小13箩利洗澡无码视频网站| 国产精品久久久久久无毒不卡 | 不卡一区二区三区四区视频| 精品人妻二区中文字幕| 国产偷国产偷亚洲高清午夜| 乱码精品一区二区亚洲区| 大肉大捧一进一出好爽视频mba | 渝北区| 18av千部影片| 日本在线视频网站www色下载| 激情国产一区二区三区四区| 在线精品视频一区二区三四|