第一题:找素数
![](https://i-blog.csdnimg.cn/blog_migrate/3877355a1ff1d910e7006139c72b0de2.png)
解法:使用筛法进行 筛选, 很模板的题目。
![](https://i-blog.csdnimg.cn/blog_migrate/f3041912b82facd075f0a86da1e4833c.png)
public class Main {
static int N = (int)1e7;
static int[] primes = new int[N];
static boolean[] st = new boolean[N];
static int cnt;
static void getPrimes(int n) {
for(int i = 2; i <= n; i++) {
if(!st[i]) {
primes[++cnt] = i;
}
for(int j = 1; primes[j] <= n/i; j++) {
st[primes[j]*i] = true;
if(i % primes[j] == 0) break;
}
}
}
public static void main(String[] args) {
// getPrimes(N-10);
// System.out.println(primes[(int)1e5+2]);
System.out.println(1299743);
}
}
第二题:图书排列
![](https://i-blog.csdnimg.cn/blog_migrate/e7cf974b4849d324fbc1bd5e47378d35.png)
第三题:日志统计
![](https://i-blog.csdnimg.cn/blog_migrate/cec7652cc143844df3a2d8070bef3df3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/c07efa46512f06cb15ef39dc57a76bef.png)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int N = (int)1e5 + 10;
static List<Point> list = new ArrayList<>();
static int[] a = new int[N];
static class Point{
int x, y;
public Point(int x, int y){
this.x = x;
this.y = y;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" +");
int n = Integer.parseInt(s[0]);
int d = Integer.parseInt(s[1]);
int k = Integer.parseInt(s[2]);
for(int i = 1; i <= n; i++){
s = br.readLine().split(" +");
int ts = Integer.parseInt(s[0]);
int id = Integer.parseInt(s[1]);
list.add(new Point(ts, id));
}
//
// for(int i = 0; i < list.size(); i++){
// Point t = list.get(i);
// System.out.println(t.x + " " + t.y);
// }
list.sort(new Comparator<Point>() {
@Override
public int compare(Point o1, Point o2) {
if(o1.x != o2.x){
return o1.x - o2.x;
}
return o1.y - o2.y;
}
});
Set<Integer> set = new TreeSet<>();
for(int i = 0, j = 0; i <= j && j < list.size(); i++){
Point t1 = list.get(i);
Point t2 = list.get(j);
// System.out.println();
// System.out.println(i + " 111 ");
while(t1.x + (d-1) >= t2.x && j < list.size()){
// System.out.println(i + " " + j);
a[t2.y]++;
if(a[t2.y] >= k) {
set.add(t2.y);
}
j++;
if(j < list.size())
t2 = list.get(j);
}
a[t1.y]--;
}
for(int num: set){
System.out.println(num);
}
}
}
//10 100 3
//30475 40668
//99004 84235
//51780 98028
//23121 8789
//78716 20034
//78719 20034
//78713 20034
//30519 40668
//30459 40668
//53454 97067
第四届:杨辉三角
过几天搞搞
~~~~事多,脑瓜疼。
不放弃一丝希望