本文主要是介绍CSP-风险人群筛查Python-Java-C++实现(100分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
CSP-风险人群筛查Python-Java-C++实现(100分)
问题描述
C++源代码
#include<iostream>using namespace std;
const int maxt=1000;
int dangerz[4];
int n,k,t;
int pnum=0;
int snum=0;struct pos{int x;int y;
};pos posarr[maxt];void Init(){cin>>n>>k>>t;for(int i=0;i<4;i++){cin>>dangerz[i];}
}bool pass(int x,int y){if(x>=dangerz[0]&&x<=dangerz[2]&&y<=dangerz[3]&&y>=dangerz[1]){return true;}else{return false;}
}bool stay(int index){// cout<<"index"<<index<<endl;if(index+k>t){return false;}else{for(int i=0;i<k;i++){if(pass(posarr[i+index].x,posarr[i+index].y)==false){// cout<<"false"<<i+index<<endl;return false;}}return true;}
}void check(){bool pflag;bool sflag;bool flag;for(int k=0;k<n;k++){pflag=false;sflag=false;flag=true;for(int i=0;i<t;i++){cin>>posarr[i].x>>posarr[i].y;}for(int i=0;i<t;i++){pflag=pass(posarr[i].x,posarr[i].y);if(pflag&&flag){pnum++;flag=false;}if(pflag==true){sflag=stay(i);if(sflag){snum++;break;}}}}cout<<pnum<<endl;cout<<snum<<endl;
}int main(){Init();check();return 0;
}
Python源代码
# Screening.py
n,k,t,xl,yd,xr,yw = map(int,input().split())pnum=0
snum=0def Ispass(x,y):if x>=xl and y >= yd and x <= xr and y <= yw:return Trueelse:return Falsefor i in range(n):sites=list(map(int,input().split()))pflag=Falsem=0while True:cnum=0while m<2*t and Ispass(sites[m],sites[m+1]):m+=2cnum+=1pflag=Truem+=2if cnum>=k:snum+=1breakif m>=2*t:breakif pflag:pnum+=1print(pnum)
print(snum)
Java源代码
import java.util.ArrayList;
import java.util.Scanner;class Pos{public int x;public int y;public Pos(int x,int y) {this.x=x;this.y=y;}
}public class Main {static int pnum=0;static int snum=0;static int danger[] = new int [4];public boolean Ispass(int x,int y){if(x>=danger[0]&&x<=danger[2]&&y>=danger[1]&&y<=danger[3]) {return true;}else {return false;}}public static void main(String argc[]) {int tempx,tempy;int cnum;//实际驻留的时间boolean pflag=false;@SuppressWarnings("resource")Scanner sc = new Scanner(System.in);Main test=new Main();int n=sc.nextInt();int k=sc.nextInt();int t=sc.nextInt();for(int i=0;i<4;i++) {danger[i]=sc.nextInt();}for(int i=0;i<n;i++) {ArrayList <Pos> arrayList = new ArrayList<>();for(int j=0;j<t;j++) {tempx=sc.nextInt();tempy=sc.nextInt();Pos pos=new Pos(tempx,tempy);arrayList.add(pos);}pflag=false;int j=0;do {cnum=0;while(j<arrayList.size() && test.Ispass(arrayList.get(j).x,arrayList.get(j).y)) {cnum++;j++;pflag=true;}if(cnum>=k) {Main.snum++;break;}j++;}while(j<arrayList.size());if(pflag) {Main.pnum++;}}System.out.println(Main.pnum);System.out.println(Main.snum);
}
}
这篇关于CSP-风险人群筛查Python-Java-C++实现(100分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!