本文主要是介绍CSP 202009-2 风险人群筛查,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:
计算机软件能力认证考试系统http://118.190.20.162/view.page?gpid=T112
【分析】这个就是遍历经过的点判断是否在矩形框的范围内,用一个变量记录连续点的个数,只要有一个点在范围内就说明经过了,把flag1设为1,当连续点的个数超过k时把flag2设为1即可。
import java.util.Scanner;public class Main {public static void main(String[] args) {int n, k, t, x1, y1, x2, y2;int ans1 = 0, ans2 = 0;Scanner scanner = new Scanner(System.in);n = scanner.nextInt();k = scanner.nextInt();t = scanner.nextInt();x1 = scanner.nextInt();y1 = scanner.nextInt();x2 = scanner.nextInt();y2 = scanner.nextInt();int i, j, z, a, b, con, flag1, flag2;for(z = 0; z < n; z++){con = 0;flag1 = 0;flag2 = 0;for(i = 0; i < t; i++){a = scanner.nextInt();b = scanner.nextInt();if(a >= x1 && a <= x2 && b >= y1 && b <= y2){con++;flag1 = 1;if(con >= k) flag2 = 1;}else{con = 0;}}if(flag2 == 1) {ans2++;}if(flag1 == 1) {ans1++;}}System.out.println(ans1);System.out.println(ans2);}}
这篇关于CSP 202009-2 风险人群筛查的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!