202009-2 Screening of risk population (Java 100)

  • Question link : Screening of risk population

  • Problem analysis : solve by simulation method.

  • Program description : n indicates the number of residents; k indicates that the continuous k coordinates in the constraint are located in the rectangle; t indicates the t moments of each inhabitant; xl, yd, xr, yu indicate the coordinates of the lower left corner and the upper right corner of the rectangle

  • Program code :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Reader {
    
    
    static StringTokenizer token =new StringTokenizer("");
    static BufferedReader  reader   =new BufferedReader (new InputStreamReader(System.in)) ;
    static String nextLine() throws IOException {
    
    
        return reader.readLine() ;
    }
    static  String next() throws IOException {
    
    
        while(!token.hasMoreTokens()) {
    
    
            token =new StringTokenizer(reader.readLine()) ;
        }
        return token.nextToken() ;
    }

    static int nextInt() throws IOException {
    
    
        return Integer.parseInt(next()) ;
    }
    static double nextDouble() throws IOException {
    
    
        return Double.parseDouble(next()) ;
    }

}

public class Main {
    
    

	public static void main(String[] args) throws IOException {
    
    
		int n = Reader.nextInt();
		int k = Reader.nextInt();
		int t = Reader.nextInt();
		int xl = Reader.nextInt();
		int yd = Reader.nextInt();
		int xr = Reader.nextInt();
		int yu = Reader.nextInt();
		int passer = 0;//记录经过的人数
		int stayer = 0;//记录逗留的人数
		for(int i=0;i<n;i++) {
    
    
			boolean flag1 = false;
			boolean flag2 = false;
			int count = 0;
			for(int j=0;j<t;j++) {
    
    
				int x = Reader.nextInt();
				int y = Reader.nextInt();
				if((x>=xl&&x<=xr)&&(y>=yd&&y<=yu)) {
    
    
					flag1 = true;
					count++;
				}else{
    
    
					count = 0;
				}
				
				if(count==k) {
    
    
					flag2 = true;
				}
			}
			
			if(flag1) {
    
    
				passer++;
			}
			if(flag2) {
    
    
				stayer++;
			}
		}
		
		System.out.println(passer);
		System.out.println(stayer);
	}

}

Guess you like

Origin blog.csdn.net/qq_43229056/article/details/109056203