标签:char ch Cow int Lineup USACO2013JAN freopen time include
题意:一串数字,选出k种血统的奶牛,并把他们全部从队列中赶走,使其连续段最大(即一段中数字的种类<=k+1)
吐槽:想找个双指针的题学习;还用到离散化,刚好复习一下昨天学到的map
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<map> using namespace std; char getc(){ static char buf[1<<14],*p1=buf,*p2=buf; return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,1<<14,stdin),p1==p2)?EOF:*p1++; } int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } #define ll long long #define ull unsigned long long const int inf=0x7f7f7f7f; const int N=100005; map<int, int> p; int n, k, js=0, tot=0, ans=0; int a[N], cnt[N]; int main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); // printf("%.3lf M\n",(double)sizeof(/*szm*/)/(1<<20)); // clock_t start_time=clock(); scanf("%d%d",&n,&k); for(int i=1; i<=n; i++){ a[i]=read(); if(!p[a[i]]) p[a[i]] = ++js; } for(int l=1,r=1; r<=n; r++){ if(cnt[p[a[r]]]==0) tot++; cnt[p[a[r]]]++; while(tot==k+2){ cnt[p[a[l]]]--; if(cnt[p[a[l]]]==0) tot--; l++; } ans = max(ans, cnt[p[a[r]]]); } printf("%d\n",ans); // clock_t end_time=clock(); //cout<<"Running time is:"<<static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000<<"ms"<<endl; fclose(stdin);fclose(stdout); return 0; }
标签:char,ch,Cow,int,Lineup,USACO2013JAN,freopen,time,include 来源: https://www.cnblogs.com/EvfX/p/15937875.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。