Poj1218_THE DRUNK JAILER(水题)

PyTorch广播机制:高效张量运算的核心原理与实战应用 在深度学习与科学计算中,张量运算是基础操作。广播机制是一种允许不同形状张量进行逐元素运算的底层原理,它通过虚拟扩展而非物理复制数据,实现了内存与计算效率的显著提升。这一机制是向量化计算的核心,能充分利用GPU并行能力,加速模型训练与推理。在PyTorch和NumPy等框架中,广播被广泛应用于数据归一化、参数更新、注意力计算等场景。本文以PyTorch为例,深入解析广播的黄金法则与内存视图实现,并探讨其在深度学习中的典型应用与常见陷阱,帮助开发者掌握这一提升代码性能的关键技术。 阅读详情

一、Description

A certain prison contains a long hall of n cells, each right next to each other. Each cell has a prisoner in it, and each cell is locked.
One night, the jailer gets bored and decides to play a game. For round 1 of the game, he takes a drink of whiskey,and then runs down the hall unlocking each cell. For round 2, he takes a drink of whiskey, and then runs down the
hall locking every other cell (cells 2, 4, 6, ?). For round 3, he takes a drink of whiskey, and then runs down the hall. He visits every third cell (cells 3, 6, 9, ?). If the cell is locked, he unlocks it; if it is unlocked, he locks it. He
repeats this for n rounds, takes a final drink, and passes out.
Some number of prisoners, possibly zero, realizes that their cells are unlocked and the jailer is incapacitated. They immediately escape.
Given the number of cells, determine how many prisoners escape jail.

Input

The first line of input contains a single positive integer. This is the number of lines that follow. Each of the following lines contains a single integer between 5 and 100, inclusive, which is the number of cells n.

Output

For each line, you must print out the number of prisoners that escape when the prison has n cells.

二、问题分析

        此题属于小弟的消暑计划之一,通俗点就是水题。题意通俗易懂,解题没什么难度,要的就是这样的效果啊。哈哈哈!

三、Java代码

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		int times=cin.nextInt();
		for(int i=0;i<times;i++){
			int n=cin.nextInt();
			boolean[] b=new boolean[n+1];
			int num=0;
			for(int l=1;l<=n;l++){
				b[l]=true;
			}
			for(int m=1;m<=n;m++){
				for(int j=2;j<=n;j++){
					if(b[m] && m%j==0){
						b[m]=false;
					}else if( !b[m] && m%j==0){
						b[m]=true;
					}
				}
			}
			for(int j=1;j<=n;j++){
				if(b[j])
					num++;
			}
			System.out.println(num);
		}
	}
}


433M无线遥控器EV1527协议解码实战:从逻辑分析到代码优化 本文详细解析了433M无线遥控器EV1527协议的实战解码过程。从使用逻辑分析仪抓取波形、理解同步头与数据位编码原理开始,逐步深入代码实现。文章重点对比了原始定时器轮询法的痛点,并提出了基于“边沿捕获+时间戳”的优化方案,构建了高效、可移植且具备抗干扰能力的解码引擎,最后分享了跨平台移植的核心技巧。 阅读详情

相关推荐

stata:stata软件教程(人大十八讲)(1) 第一章 stata入门

第一章 stata入门1.1 安装1.2 启用和退出1.3 打开和查看数据1.4 寻求帮助与网络资源1.5 命令示例1.6 几个环境设置1.7 复习与练习1.8 附录 注:教材为:Stata 统计分析教程 stata软件教程(人大十八讲) 中国人民大学出版社 陈传波 1.1 安装 1.2 启用和退出 1.3 打开和查看数据 1.4 寻求帮助与网络资源 1.5 命令示例 1.6 几个环境设置 1.7 复习与练习 1.8 附录 ...

qq_47805483的博客 1万+

【C语言】1218 THE DRUNK JAILER

A certain prison contains a long hall of n cells, each right next to each other. Each cell has a prisoner in it, and each cell is locked.One night, the jailer gets bored and decides to play a game. F...

weixin_30810583的博客 180

ArcGIS 10.2.2自带Python 2.7.5环境配置全攻略:从pip安装到gdal、arcpy调用

本文详细指导如何在ArcGIS 10.2.2自带的Python 2.7.5环境中进行高效配置。核心内容包括安装pip包管理器、部署gdal等关键地理数据处理库,并确保arcpy模块的无缝调用。通过解决路径配置与PyCharm集成问题,帮助用户在此经典环境中构建稳定、兼容的地理信息自动化工作流,有效连接ArcGIS桌面功能与Python脚本编程。

moon9的博客 768

POJ 1218 THE DRUNK JAILER【类开灯问题】

THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27268   Accepted: 16933 Description A certain prison contains a long hall of n cells, each r

AC_Dreameng 1715

TensorFlow实战:5步搞定因果推断模型TARNet(附完整代码)

本文提供了一份基于TensorFlow的TARNet因果推断模型实战指南。通过五个清晰步骤,从数据预处理、模型构建到训练评估,详细讲解了如何利用深度模型解决营销评估、疗效分析等场景中的因果效应估计问题,并附有完整代码解决样本不平衡等工程挑战。

python9snake的博客 417

风力发电机缺陷检测平台

风力发电机缺陷检测平台相关内容展示

weixin_39779415的博客 1111

POJ 1218 THE DRUNK JAILER

时间限制:1000ms内存限制:65536kB描述A certain prison contains a long hall of n cells, each right next to each other. Each cell has a prisoner in it, and each cell is locked. One night, the jailer gets b...

weixin_30757793的博客 251

国产SR8201F以太网PHY芯片调试避坑指南:从机贴失败到杜邦线救场的实战记录

本文详细介绍了国产SR8201F以太网PHY芯片的调试避坑指南,涵盖硬件设计、PCB布局、SMT贴片及软件驱动等关键环节。通过实战案例解析,帮助工程师解决MII/RMII接口配置、电源设计、信号完整性等典型问题,提升以太网通信稳定性与EMC性能。

c6d7e8f9g的博客 1216

POJ 1218 THE DRUNK JAILER (题目虽然简单,但是学到了很多)

THE DRUNK JAILER A certain prison contains a long hall of n cells, each right next to each other. Each cell has a prisoner in it, and each cell is locked. One night, the jailer gets bored

Keep trying, keep going 903

Sony微单相机alpha6000 wifi远程控制(1)

引言 Sony’s Camera Remote API beta SDK allows you to control a number of Sony cameras, including Sony Action cams, Sony Alpha cameras and Lens Style cameras, wirelessly from another device. 索尼于2017年三月Re...

markfuk996的博客 4966

华为OD机试 - 天然蓄水库(Java 2025 A卷 100分)

例如,当山脉为s = [3, 1, 2]时,则选取s[0]和s[2]作为水库边界,则蓄水量为1,此时输出:0 2:1。选取下标 0(高度 3)与 2(高度 2)为边界,水位为 min(3,2)=2;选取山脉上两个点作为蓄水库的边界,则边界内的区域可以蓄水,蓄水量需排除山脉占用的空间。经过分析,选取s[1]和s[6]时,水库蓄水量为19(3 + 7 + 4 + 5)。当存在合理的水库边界时,输出左边界、空格、右边界、英文冒号、蓄水量;当山脉`s = [3, 2, 1]时,不存在合理的边界,此时输出:0。

学Java,找哪吒 939

POJ 1218 THE DRUNK JAILER(水题)

题目链接:http://poj.org/problem?id=1218 题目

Strawberry_szj的专栏 581

华为嵌入式面试题及参考答案(持续更新)

异步是指在程序执行过程中,某些任务不需要等待立即完成就可以继续执行其他任务的过程。在计算机编程中,异步通常用于处理长时间运行的操作,如文件读写、网络通信等,以避免阻塞主线程。异步处理通常涉及到回调函数、事件循环、协程或未来的概念。使用宏定义来避免命名冲突。#else#endif堆和栈是计算机程序中用于存储数据的两种不同类型的内存区域。

大模型大数据攻城狮的专栏 2485

【水题】POJ-1218 THE DRUNK JAILER

我是一个菜鸟,写这个完全是为了记录自己的历程,也为很好的督促自己不放弃,不抛弃。 题目原文: THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17702   Accepted: 11266

GYTAnonymous的专栏 993

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

THE DRUNK JAILER - POJ 1218 水题

THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22919   Accepted: 14449 Description A certain prison contains a long hall of n cells, each

提比的强行AC 685

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

[1218]THE DRUNK JAILER (水题)POJ

 THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23597   Accepted: 14853 Description A certain prison contains a long hall of n cells, each

jiangyongy的专栏 568

POJ1218 THE DRUNK JAILER

一、题目信息 THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19482   Accepted: 12304 Description A certain prison contains a long hall of n

FreeCoder的专栏 4278

THE DRUNK JAILER POJ - 1218

THE DRUNK JAILER POJ - 1218题目描述 A certain prison contains a long hall of n cells, each right next to each other. Each cell has a prisoner in it, and each cell is locked. One night, the jailer gets b

退役的铜牌狗 433

POJ 1218 THE DRUNK JAILER

THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28016   Accepted: 17376 Description A certain prison contains a long hall of n cells, each r

weixin_37571609的博客 258

POJ1218THE DRUNK JAILER 快速和一般方法两种解法

一道数论题,虽然模拟也可行,但效率和代码长度明显不如利用数论知识求解。记得之前在哪本书上看到一个类似的问题,不过那个不是狱卒,而是邮差,不是监狱,而是邮箱,其实实质是一样的。本题思路:访问次数为奇数的牢房即最终为开着的牢房,问题转而求给定数以内因子数为奇数的数,而只有完全平方数才有奇数个因子:假设m为n的一个因子,则n/m为n的另一个因子,这两个因子形成一对,若因子数为奇数,则必有某个m=n/m,即n=m*m,故问题最终转为求给定数以内完全平方数个数。

恰同学少年 1696

POJ 1218 THE DRUNK JAILER(醉汉看守)

THE DRUNK JAILER Time Limit: 1000MS Memory Limit: 10000K Description A certain prison contains a long hall of n cells, each right next to each other. Each cell has a...

HouRui2000的博客 299

poj 1218THE DRUNK JAILER

/* Name:poj 1218THE DRUNK JAILER Author:Unimen Date: 1/05/2011 9:34 Description:水题*/#include #include using namespace std;int anCells[105];int main(){ int m, n, nCount; i

Unimen的专栏 502
上一篇: Poj1298_The Hardest Problem Ever(水题)
下一篇: Poj1258_Agri-Net(最小生成树)
TaiSung
博客等级 码龄15年 49粉丝 132原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值