A 拨开题意就是求,最多重复的时间,然后记录下个数就行、
#include<iostream>
#include<set>
#include<string>
#include<cstdio>
using namespace std;
int main() {
int n;
set<string> myset;
set<string>::iterator it;
string str;
while(~scanf("%d",&n)) {
int cnt = 1;
getchar();
int ans = 1;
for(int i = 0 ; i < n ; i ++) {
getline(cin , str);
if(myset.find(str)!=myset.end()) {
cnt++;
if(cnt > ans) ans = cnt;
} else cnt = 1;
myset.insert(str);
}
cout<<ans<<endl;
}
}
C 质数打表+二分枚举
#include<iostream>
#include<set>
#include<string>
#include<cstdio>
using namespace std;
int prime[1000010] = {0};
int cnt[1000010];
int a , b , K;
void Init() {
int i , j;
prime[0] = 1;
prime[1] = 1;
for(i = 2 ; i*i< 1000010 ; i ++)
if(!prime[i])
for(j = i + i ; j < 1000010 ; j += i)
prime[j] = 1;
cnt[0] = 0;
cnt[1] = 0;
for(i = 2 ; i < 1000010 ; i ++)
if(!prime[i]) cnt[i] = cnt[i-1] + 1;
else cnt[i] = cnt[i-1];
} //打表
bool check(int mid) {
for(int x = a ; x <= b-mid+1 ; x ++) {
if((cnt[x+mid-1]-cnt[x-1]) < K) return false;
}
return true;
}//检查区间内是否全满足质数个数大于等于K
int main() {
int l , x , ans , tmp , c;
Init();
while(~scanf("%d%d%d",&a,&b,&K)) {
int L , R , mid;
L = 1 , R = b - a + 1;
int ans = 0;
while(L<=R) {//二分 l
mid = (L+R)>>1;
if(check(mid)) {
ans = mid;
R = mid - 1;
} else L = mid + 1;
}
if(ans && check(ans)) printf("%d\n",ans);
else printf("-1\n");
}
}