20-09-02(风险人群筛查)

风险人群筛查

第一次

可以通过测试用例,但结果为:错误

//示例一
//5 2 6 20 40 100 80
//100 80 100 80 100 80 100 80 100 80 100 80
//60 50 60 46 60 42 60 38 60 34 60 30
//10 60 14 62 18 66 22 74 26 86 30 100
//90 31 94 35 98 39 102 43 106 47 110 51
//0 20 4 20 8 20 12 20 16 20 20 20

//示例二
//1 3 8 0 0 10 10
//-1 -1 0 0 0 0 -1 -1 0 0 -1 -1 0 0 0 0
import java.util.*;
        public class csp_20_09_02{
    
    
            public static void main(String[] args){
    
    
                Scanner input = new Scanner(System.in);
                int n = input.nextInt();
                int k = input.nextInt();
                int t = input.nextInt();
                int xl = input.nextInt();
                int yl = input.nextInt();
                int xr = input.nextInt();
                int yr = input.nextInt();
                int m = 2*t;
                int[][] person = new int[n][m];
                int jingguo = 0,douliu = 0;
                for(int i =0;i<n;i++){
    
    
                    for(int j =0;j<m;j++){
    
    
                        person[i][j] = input.nextInt();
                    }
                    //一个人的输入完成 开始判断
                    int[] temp = new int[t];
                    //int w = 0;
                    for(int p =0;p<m;){
    
    
                        System.out.print(p/2+" ");
                        //该时经过了高危地区
                        if((person[i][p]>=xl && person[i][p+1]>=yl)&&(person[i][p]<=xr && person[i][p+1]<= yr)){
    
    
                            temp[p/2] = 1;
                            //System.out.println(i+" "+p+"时刻"+"经过了高危地区:"+person[i][p]+" "+ person[i][p+1]);
                        }
                        p+=2;
                    }
//                    for(int q=0;q<t;q++)
//                    System.out.print(temp[q]+" ");
                    //连续多少天
                    int max = 0;
                    for(int q = 0;q<t;q++){
    
    
                        int key = 0;
                        if(temp[q] == 1){
    
    
                            while( q<t && temp[q] == 1){
    
    
                                key++;
                                q++;
                            }
                            if(max < key)
                                max = key;
                        }
                    }
                    if(max>=k){
    
    
                        douliu++;
                    }else{
    
    
                        jingguo++;
                    }
                }//输入结束
                //输出结果
                System.out.println(jingguo);
                System.out.println(douliu);
            }//退出主函数
        }

第二次(正确)

只修改了两个地方(已做出标记)

import java.util.*;
        public class Main{
    
    
            public static void main(String[] args){
    
    
                Scanner input = new Scanner(System.in);
                int n = input.nextInt();
                int k = input.nextInt();
                int t = input.nextInt();
                int xl = input.nextInt();
                int yl = input.nextInt();
                int xr = input.nextInt();
                int yr = input.nextInt();
                int m = 2*t;
                int[][] person = new int[n][m];
                int jingguo = 0,douliu = 0;
                for(int i =0;i<n;i++){
    
    
                    for(int j =0;j<m;j++){
    
    
                        person[i][j] = input.nextInt();
                    }
                    //一个人的输入完成 开始判断
                    int[] temp = new int[t];
                    //int w = 0;
                    for(int p =0;p<m;){
    
    
                        //该时经过了高危地区
                        if((person[i][p]>=xl && person[i][p+1]>=yl)&&(person[i][p]<=xr && person[i][p+1]<= yr)){
    
    
                            temp[p/2] = 1;
                            
                        }
                        p+=2;
                    }

                    //连续多少天
                    int max = 0;
                    for(int q = 0;q<t;q++){
    
    
                        int key = 0;

                        if(temp[q] == 1){
    
    
                            while( q<t && temp[q] == 1){
    
    
                                key++;
                                q++;
                            }
                            if(max < key)
                                max = key;

                        }

                    }
                    if(max>=k){
    
    
                        douliu++;
                        jingguo++; // *******修改一 增加 jingguo++ 
                    }else
                         if(max >= 1){
    
     //*******修改二  增加判断 max>=1
                        jingguo++;
                    }
                }//输入结束

                //输出结果
                System.out.println(jingguo);
                System.out.println(douliu);
            }//退出主函数
}

猜你喜欢

转载自blog.csdn.net/qq_51985653/article/details/120831940