CSP-风险人群筛查Python-Java-C++实现(100分)

2024-03-31 16:08

本文主要是介绍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分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/864734

相关文章

python panda库从基础到高级操作分析

《pythonpanda库从基础到高级操作分析》本文介绍了Pandas库的核心功能,包括处理结构化数据的Series和DataFrame数据结构,数据读取、清洗、分组聚合、合并、时间序列分析及大数据... 目录1. Pandas 概述2. 基本操作:数据读取与查看3. 索引操作:精准定位数据4. Group

Python pandas库自学超详细教程

《Pythonpandas库自学超详细教程》文章介绍了Pandas库的基本功能、安装方法及核心操作,涵盖数据导入(CSV/Excel等)、数据结构(Series、DataFrame)、数据清洗、转换... 目录一、什么是Pandas库(1)、Pandas 应用(2)、Pandas 功能(3)、数据结构二、安

Spring Boot集成/输出/日志级别控制/持久化开发实践

《SpringBoot集成/输出/日志级别控制/持久化开发实践》SpringBoot默认集成Logback,支持灵活日志级别配置(INFO/DEBUG等),输出包含时间戳、级别、类名等信息,并可通过... 目录一、日志概述1.1、Spring Boot日志简介1.2、日志框架与默认配置1.3、日志的核心作用

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

破茧 JDBC:MyBatis 在 Spring Boot 中的轻量实践指南

《破茧JDBC:MyBatis在SpringBoot中的轻量实践指南》MyBatis是持久层框架,简化JDBC开发,通过接口+XML/注解实现数据访问,动态代理生成实现类,支持增删改查及参数... 目录一、什么是 MyBATis二、 MyBatis 入门2.1、创建项目2.2、配置数据库连接字符串2.3、入

Springboot项目启动失败提示找不到dao类的解决

《Springboot项目启动失败提示找不到dao类的解决》SpringBoot启动失败,因ProductServiceImpl未正确注入ProductDao,原因:Dao未注册为Bean,解决:在启... 目录错误描述原因解决方法总结***************************APPLICA编

深度解析Spring Security 中的 SecurityFilterChain核心功能

《深度解析SpringSecurity中的SecurityFilterChain核心功能》SecurityFilterChain通过组件化配置、类型安全路径匹配、多链协同三大特性,重构了Spri... 目录Spring Security 中的SecurityFilterChain深度解析一、Security

Python安装Pandas库的两种方法

《Python安装Pandas库的两种方法》本文介绍了三种安装PythonPandas库的方法,通过cmd命令行安装并解决版本冲突,手动下载whl文件安装,更换国内镜像源加速下载,最后建议用pipli... 目录方法一:cmd命令行执行pip install pandas方法二:找到pandas下载库,然后

Redis客户端连接机制的实现方案

《Redis客户端连接机制的实现方案》本文主要介绍了Redis客户端连接机制的实现方案,包括事件驱动模型、非阻塞I/O处理、连接池应用及配置优化,具有一定的参考价值,感兴趣的可以了解一下... 目录1. Redis连接模型概述2. 连接建立过程详解2.1 连php接初始化流程2.2 关键配置参数3. 最大连

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.