日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 芯聞號 > 充電吧
[導(dǎo)讀]【CF簡介】提交鏈接:CF 645C題面:C. Enduring Exodus time limit per test 2 seconds memory limit per test 256 me

【CF簡介】

提交鏈接:CF 645C


題面:


C. Enduring Exodus time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and hisk cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists ofn rooms located in a row, some of which are occupied.

Farmer John wants to book a set of k?+?1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j?-?i|. Help Farmer John protect his cows by calculating this minimum possible distance.

Input

The first line of the input contains two integers n andk (1?≤?k?<?n?≤?100?000)?— the number of rooms in the hotel and the number of cows travelling with Farmer John.

The second line contains a string of length n describing the rooms. Thei-th character of the string will be '0' if thei-th room is free, and '1' if thei-th room is occupied. It is guaranteed that at leastk?+?1 characters of this string are '0', so there exists at least one possible choice ofk?+?1 rooms for Farmer John and his cows to stay in.

Output

Print the minimum possible distance between Farmer John's room and his farthest cow.

Examples Input

7?2
0100100

Output

2

Input

5?1
01010

Output

2

Input

3?2
000

Output

1

Note

In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms.

In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2.

In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.












--------------------------------------------------------------------------------------啦啦啦,我是分割線--------------------------------------------------------------------------------------------------------------

題意:

??? 一個農(nóng)夫帶著k頭牛去住店,(人一間,每牛一間)已知該旅店共有n間房,其中部分房間已有人住,房間住宿情況由01串表示,0表示空,1表示已有人住,剩余房間足夠容納(k+1)頭牛/人。為了保障牛的安全,希望人住的房間離最遠(yuǎn)的牛的房間位置盡量小,輸出最小距離。


思路:

??? 很明顯為了讓人住的離最遠(yuǎn)的牛最近,那么最后這批人牛住的房間肯定是連續(xù)的(不算原有的住宿人員),且人住的位置離中心點越近越好。首先,枚舉住宿的左區(qū)間,如果左端點已有人住,則跳過該點,如果空,則二分以該點為左端點,空閑房間數(shù)為k+1的最左位置。隨后在這個區(qū)間內(nèi),開始尋找空閑的最中心位置(距離遠(yuǎn)的那端盡量?。?,利用區(qū)間長度奇偶性設(shè)置兩個指針p1,p2的初始位置,隨后分別往兩端移動,因為一定有空閑位置,且兩指針同時移動,不會出現(xiàn)越界情況。最后找到一個解,則計算最遠(yuǎn)距離,若小于最優(yōu)值,則更新。


代碼:


#include#include#include#includeusing?namespace?std;
char?s[100010];
int?room[100010];
int?main()
{
????int?n,k,len,le,ri,border,ans,pos;
	//讀入
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	room[0]=0;
	for(int?i=1;i<=n;i++)
	{
		//前綴和
		if(s[i-1]-'0')
			room[i]=room[i-1];
		else
			room[i]=room[i-1]+1;
	}
	//設(shè)置一個肯定會被更新的最大值
	ans=10e6;
	for(int?i=1;i<=n;i++)
	{
		//該點已有人住
	???if(room[i]==room[i-1])
		???continue;
???????le=i;
	???ri=n;
	???border=-1;
	???//二分右區(qū)間
	???while(le>1;
		???if(room[mid]-room[i-1]>k)
		???{

			???border=mid;
			???ri=mid-1;
		???}
		???else
			???le=mid+1;
	???}
	???//如果能找到k+1個房間
	???if(border!=-1)
	???{
?????????int?len=(border-i),p1,p2;
		?//根據(jù)區(qū)間長度奇偶性,設(shè)置p1,p2
?????????if(len%2)
		?{
			?p1=(border+i)>>1;
			?p2=(border+i)/2+1;
		?}
		?else
		?{
			?p1=p2=(border+i)>>1;
		?}
		?//尋找最先出現(xiàn)空閑房間
		?while(1)
		?{
			?if((room[p1]!=room[p1-1]))
		????{
				pos=p1;
				break;
			}
			?else?if(room[p2]!=room[p2-1])
			?{
				?pos=p2;
				?break;
			}
			?p1--;
			?p2++;
		?}
?????????//更新最優(yōu)值
		?ans=min(ans,max(pos-i,border-pos));
	???}
	???//說明剩下,已無可能有k+1個房間
	???else
		???break;
	}
	printf("%dn",ans);
	return?0;
}





本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀

公司憑借其面向地面與非地面網(wǎng)絡(luò)的 AI 驅(qū)動、云原生移動解決方案的杰出創(chuàng)新斬獲殊榮華盛頓和得克薩斯州理查森, March 31, 2026 (GLOBE NEWSWIRE) -- 致力于構(gòu)建 AI 原生設(shè)計移動網(wǎng)絡(luò)的軟...

關(guān)鍵字: 衛(wèi)星 移動 創(chuàng)新獎 NI

前 Amazon Robotics 高管出任全球生產(chǎn)戰(zhàn)略部負(fù)責(zé)人,助力公司擴張 休斯敦, April 01, 2026 (GLOBE NEWSWIRE) -- 具身 AI 領(lǐng)域新一代領(lǐng)軍企業(yè)?Persona AI 今...

關(guān)鍵字: VI RS AN AI

可持續(xù)發(fā)展與企業(yè)責(zé)任實踐再獲國際資本市場認(rèn)可 香港2026年3月31日 /美通社/ -- 全球領(lǐng)先的互聯(lián)網(wǎng)社區(qū)創(chuàng)建者 - 網(wǎng)龍網(wǎng)絡(luò)控股有限公司 ("網(wǎng)龍"...

關(guān)鍵字: MSC AI 可持續(xù)發(fā)展 網(wǎng)絡(luò)游戲

當(dāng)前,全球半導(dǎo)體競爭日益激烈,作為芯片薄膜沉積工藝的核心耗材,高純度靶材的制造水平直接關(guān)系芯片良率,其技術(shù)攻堅與產(chǎn)能提升面臨嚴(yán)峻挑戰(zhàn)。近日,江豐電子在年報中指出,黃湖靶材工廠的建設(shè)穩(wěn)步推進(jìn),成為其高標(biāo)準(zhǔn)產(chǎn)能布局的重要一環(huán)...

關(guān)鍵字: 半導(dǎo)體

2026 年 3 月 31 日,華為投資控股有限公司正式發(fā)布 2025 年年度報告。

關(guān)鍵字: 華為 2025年年報 AI 云計算

當(dāng)?shù)貢r間 3 月 31 日,亞馬遜低軌衛(wèi)星項目Amazon Leo宣布再獲重要突破,正式與美國達(dá)美航空達(dá)成合作,將為其提供機上高速互聯(lián)網(wǎng)連接服務(wù),標(biāo)志著亞馬遜正式切入航空互聯(lián)賽道。

關(guān)鍵字: 亞馬遜 Leo 達(dá)美航空 Wi-Fi

都柏林, March 30, 2026 (GLOBE NEWSWIRE) -- 隨著企業(yè)在投資者、監(jiān)管機構(gòu)以及 ESG 承諾方面面臨的碳足跡減排壓力日益加大,企業(yè)差旅正成為一個通過微小運營調(diào)整即可產(chǎn)生顯著成效的領(lǐng)域。...

關(guān)鍵字: FOR 數(shù)字化 SI ESIM

當(dāng)?shù)貢r間 3 月 30 日,專注在軌 AI 數(shù)據(jù)中心建設(shè)的美國初創(chuàng)企業(yè) Starcloud 宣布完成 1.7 億美元融資,投后估值 11 億美元,正式躋身獨角獸行列。

關(guān)鍵字: 太空數(shù)據(jù)中心 Starcloud AI 數(shù)據(jù)中心

March 30, 2026 ---- 根據(jù)TrendForce集邦咨詢最新筆電產(chǎn)業(yè)調(diào)查,近期全球筆電出貨量進(jìn)一步出現(xiàn)轉(zhuǎn)弱的跡象,TrendForce集邦咨詢在預(yù)期終端消費動能趨緩、供應(yīng)鏈成本持續(xù)墊高的雙重影響下,正式更...

關(guān)鍵字: 筆電 供應(yīng)鏈 半導(dǎo)體
關(guān)閉