
0 点赞 评论 收藏
分享
牛客最菜没有之一:.....对啊,半个小时交卷,不过问答题过分了

0 点赞 评论 收藏
分享

0 点赞 评论 收藏
分享
2018-09-06 21:23
这还是秘密~ Java Aperture_S...:附上我的暴力代码 public class Main {
static int[] count = new int[100000+1];
static LinkedList<Integer> queue= new LinkedList<>();
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
int k = sc.nextInt();
int t = sc.nextInt();
int res = 0;
boolean first = true;
int lastNum = 0;
for(int i = 0; i < k; i++) {
int temp = sc.nextInt();
queue.offer(temp);
count[temp]++;
//System.out.println(count[temp]);
if(first && count[temp] >= t) {
res++;
first = false;
lastNum = temp;
}
}
for(int i = k; i < n; i++) {
int last = queue.poll();
count[last]--;
int temp = sc.nextInt();
queue.offer(temp);
count[temp]++;
if(count[lastNum] >= t) {
res++;
continue;
}
if(count[temp] >= t) {
res++;
lastNum = temp;
continue;
}
if(count[last] >= t) {
res++;
lastNum = last;
continue;
}
Iterator<Integer> it = queue.iterator();
while(it.hasNext()) {
int num = it.next();
if(count[num] >= t) {
res++;
lastNum = num;
break;
}
}
}
System.out.println(res);
}
}

0 点赞 评论 收藏
分享

0 点赞 评论 收藏
分享
2018-08-31 16:56
这还是秘密~ Java 0 点赞 评论 收藏
分享

0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: