[USACO13JAN] Cow Lineup (單調隊列,尺取法)

題目鏈接

Solution

尺取法板子,算是復習一波.
題中說最多刪除 \(k\) 種,那么其實就是找一個顏色種類最多為 \(k+1\) 的區間;
統計一下其中最多的顏色出現次數.
然后直接尺取法,然后每次對于 \(col[r]\) 進行統計,時間復雜度 \(O(n)\) .

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn=100008;int ans;
int n,k,col[maxn];
map <int,int>js;int main()
{scanf("%d%d",&n,&k);for(int i=1;i<=n;i++)scanf("%d",&col[i]);int now=0,l=1,r=0;while(r<=n){r++;if(!js[col[r]])now++;js[col[r]]++;while(now==k+2){js[col[l]]--;if(!js[col[l]])now--;l++;}ans=max(ans,js[col[r]]);}cout<<ans<<endl;
}

轉載于:https://www.cnblogs.com/Kv-Stalin/p/9702870.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/279277.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/279277.shtml
英文地址,請注明出處:http://en.pswp.cn/news/279277.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

智能記憶功能nest_如何設置和安裝Nest Protect智能煙霧報警器

智能記憶功能nestIf you want to add a bit more convenience and safety to your home’s smoke alarm setup, the Nest Protect comes with a handful of great features to make that a reality. Here’s how to set it up and what all you can do with it. 如果您想為您的…

網格自適應_ANSYS 非線性自適應(NLAD)網格劃分及應用舉例

文章來源&#xff1a;安世亞太官方訂閱號&#xff08;搜索&#xff1a;Peraglobal&#xff09;在復雜的結構設計分析中&#xff0c;通常很難確定在高應力區域中是否生成適當的細化網格。在做非線性大應變分析仿真時&#xff0c;可能由于單元變形過大&#xff0c;導致網格畸變&a…

js繼承優化

在看《js設計模式》中&#xff0c;作者提到了js中的兩種繼承方式&#xff1a;類繼承 或 原型繼承&#xff0c;或許是本人才疏學淺&#xff0c;竟發現一些問題。 一、類繼承 思路&#xff1a;作者的思路是使用基于類來繼承&#xff0c;并且做了一個extend函數&#xff0c;在第一…

python---[列表]lsit

內置數據結構&#xff08;變量類型&#xff09; -list -set -dict -tuple -list&#xff08;列表&#xff09; -一組又順序的數據組合 -創建列表 -空列表 list1 []        print(type(list1))        print(list1)        list2 [100]       …

喚醒計算機運行此任務_如何停止Windows 8喚醒計算機以運行維護

喚醒計算機運行此任務Windows 8 comes with a new hybrid boot system, this means that your PC is never really off. It also means that Windows has the permission to wake your PC as it needs. Here’s how to stop it from waking up your PC to do maintenance tasks…

轉整型_SPI轉can芯片CSM300詳解、Linux驅動移植調試筆記

一口君最近移植了一款SPI轉CAN的芯片CSM300A&#xff0c;在這里和大家做個分享。一、CSM300概述CSM300(A)系列是一款可以支持 SPI / UART 接口的CAN模塊。1. 簡介CSM300(A)系列隔離 SPI / UART 轉 CAN 模塊是集成微處理器、 CAN 收發器、 DC-DC 隔離電源、 信號隔離于一體的通信…

matlab練習程序(二值圖像連通區域標記法,一步法)

這個只需要遍歷一次圖像就能夠完全標記了。我主要參考了WIKI和這位兄弟的博客&#xff0c;這兩個把原理基本上該介紹的都介紹過了&#xff0c;我也不多說什么了。一步法代碼相比兩步法真是清晰又好看&#xff0c;似乎真的比兩步法要好很多。 代碼如下&#xff1a; clear all; c…

pc微信不支持flash_在出售PC之前,如何取消對Flash內容的授權

pc微信不支持flashWhen it comes to selling your old digital equipment you usually should wipe it of all digital traces with something like DBAN, however if you can’t there are some precautions you should take–here’s one related to Flash content you may h…

博客在線——Wireshark基本用法

http://blog.jobbole.com/ http://blog.jobbole.com/70907/轉載于:https://www.cnblogs.com/zhongbokun/p/9709326.html

繪制三維散點圖_SPSS統計作圖教程:三維散點圖

作者&#xff1a;豆沙包&#xff1b;審稿&#xff1a;張耀文1、問題與數據最大攜氧能力是身體健康的一項重要指標&#xff0c;但檢測該指標成本較高。研究者想根據性別、年齡、體重、運動后心率等指標建立預測最大攜氧能力的模型&#xff0c;招募了100名研究對象&#xff0c;測…

【Python】插入sqlite數據庫

import sqlite3 from datetime import datetimeconn sqlite3.connect(data.db) print("Opened database successfully")for i in range(100):time datetime.now()conn.execute("INSERT INTO test(time,url,imgPath) VALUES (?,?,?)", (time, "ww…

java數組轉list(Arrays .asList)

習慣性的錯誤代碼&#xff1a; Integer[] intArr {1,2,3}; List<Integer> lst Arrays .asList(intArr); lst.add(4); 報UnsupportedOperationException異常&#xff0c;原因是Arrays .asList() 返回的固定大小的列表&#xff0c;無法進行add、remove等操作&#xff1b;…

使用lodash防抖_什么,lodash 的防抖失效了?

戳藍字「前端技術優選」關注我們哦&#xff01;作者&#xff1a;yeyan1996https://juejin.im/post/6892577964458770445應某人的要求被迫營業&#xff0c;望各位看官不要吝嗇手中的贊-。-背景在使用 uni-app 開發小程序時&#xff0c;有個填寫表單的需求&#xff0c;包含兩個輸…

Ubuntu 12.10中的8個新功能,Quantal Quetzal

Ubuntu 12.10 has been released and you can download it now. From better integration with web apps and online services to improvements in Unity, there are quite a few changes – although none of them are huge or groundbreaking. Ubuntu 12.10已發布&#xff0c…

背單詞APP調研分析

前言&#xff1a;隨著我國網絡經濟重心向移動端的轉移&#xff0c;移動教育領域獲得的關注度在持續放大。互聯網的發展和移動設備的普及&#xff0c;我們開始在移動設備上學習&#xff0c;各種學習教育軟件如雨后春筍&#xff0c;越來越多&#xff0c;就背單詞軟件來說&#xf…

linux 提取cpio_Linux提取RPM包文件(cpio命令)詳解

在講解如何從 RPM 包中提取文件之前&#xff0c;先來系統學習一下 cpio 命令。cpio 命令用于從歸檔包中存入和讀取文件&#xff0c;換句話說&#xff0c;cpio 命令可以從歸檔包中提取文件(或目錄)&#xff0c;也可以將文件(或目錄)復制到歸檔包中。歸檔包&#xff0c;也可稱為文…

cdh中使用hue使用教程_我可以在戶外使用Philips Hue燈泡嗎?

cdh中使用hue使用教程Philips Hue lights are great to have in your house, and they can add a lot of convenience to your living space. However, what if you want to use these smart bulbs outdoors in porch lights or flood lights? Will Philips Hue bulbs work pr…

django (三) admin后臺系統

admin后臺系統 1. 安裝MySQL 1,安裝mysql: sudo apt install mysql-server (安裝過程中輸入密碼并牢記) 2,安裝后進入mysql: mysql -u用戶名 -p密碼 mysql -uroot -proot ? 3,在Django中配置和使用mysql數據庫 使用mysql數據庫&#xff0c;settings中配置如下&#xff1a; DAT…

python博客訪問量_史詩級干貨-python爬蟲之增加CSDN訪問量

AI人工智能史詩級干貨-python爬蟲之增加CSDN訪問量史詩級干貨-python爬蟲之增加CSDN訪問量搜索微信公眾號:‘AI-ming3526’或者’計算機視覺這件小事’ 獲取更多算法、機器學習干貨csdn&#xff1a;https://blog.csdn.net/baidu_31657889/github&#xff1a;https://github.com…

弄斷過河電纜_你說的是:剪斷電纜線

弄斷過河電纜Earlier this week we asked you if you’d cut the cable and switched to alternate media sources to get your movie and TV fix. You responded and we’re back with a What You Said roundup. 本周早些時候&#xff0c;我們問您是否要切斷電纜并切換到其他媒…