There are n lockers in a hallway numbered sequentially from 1 to n. Initially, all the locker doors
package xuexi;
/*
* n把锁问题
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Locker {
public static void main(String[] args) {
System.out.println("请输入N的值:");
Scanner input=new Scanner(System.in);
int t=input.nextInt();
door s=new door();
s.siwith(t);
}
}
class door{
public void siwith(int n){
int locker []=new int[n+1];
for(int i=1;i<n;i++){
locker[i]=0;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(j%i==0){
locker[j]=(locker[j]==0)?1:0;
}
}
}
for(int i=1;i<n;i++){
if(locker[i]==0){
System.out.println(i);
}
}
}
}
There are n lockers in a hallway numbered sequentially from 1 to n. Initially, all the locker doors相关推荐
- 【算法----->Locker Doors】
LockerDoors 题目 输入 输出 代码实现(Java) 例子 题目 There are n lockers in a hallway numbered sequentially from 1 ...
- SWUSTOJ #480 Locker doors
SWUSTOJ #480 Locker doors 题目 输入 输出 样例输入 样例输出 源代码 题目 There are n lockers in a hallway numbered sequen ...
- Craking the Interview-1
1.6 90度旋转NxN矩阵 Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes ...
- Google面试之快乐智力题(Cracking the Coding Interview)
问:有20瓶药,其中19瓶装的都是1.0克的药片,只有1瓶装了1.1克的药.给你一个能称出具体克数的电子秤,只允许你称一次,怎么找出那瓶不一样的? 答:如果药片足够,从第i(1<i<20) ...
- 计算机导论简答芯片,吉大计算机 - 计算机导论简答题 (2011级)
C1 2. Q: What model is the basis for today's computers? A: Von Neumann Model. 5. Q: What are the sub ...
- 正则表达式语法规则收集
turnmissile 的 Blog http://blog.csdn.net/turnmissile/ Microsoft已经把正则表达式的规则收录在了msdn里面了,有兴趣的朋友可以自己去研究一下 ...
- NYOJ-232 How to eat more Banana
How to eat more Banana 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 A group of researchers are designing a ...
- HDOJ 1069 Monkey and Banana
1:每一组X,Y,Z对应3个立方体 2:按面积从小到大DP Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- HDU 1069 Monkey and Banana 最长上升子序列进阶(动态规划)
HDU 1069(动态规划) Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
最新文章
- 使用Word2010灵活掌握文档结构
- 升级人脸识别,小鱼易连要打通企业与个人微信,重塑视频会议3.0!
- mac -- 安装OpenCV
- 安全领域新概念:安全评级服务的兴起
- 仿Gin搭建自己的web框架(五)
- python利用集合的无重复性_python集合?
- | 一文读懂迁移学习(附学习工具包)
- 在Chrome开发者工具里手动测试element focus效果
- 233. 数字 1 的个数
- Centos7中Memcached安装使用说明
- 华为API战略:规范、组织和流程驱动企业大循环
- 特征工程系列学习(零)引言
- HDU2066一个人的旅行(dijkstra)
- 越看越爽,此后统计学习不再是路人!
- 串行加法器 并行加法器 超前进位加法器
- Linux环境安装ghostscript-9.25
- 使用Unity3D引擎制作塔防类游戏(一)
- 【74HC595】STM32 74HC595驱动程序
- 《数字图像处理》学习总结及感悟:第二章数字图像基础(4)像素间的关系
- mac上免费的音频剪辑软件在哪里可以快速下载
热门文章
- 1900年 巴黎 第二届奥运会
- [Python]yield用法入门
- python怎样导入游戏库_如何安装python的游戏模块pygame
- SQL 数据类型 之 数字类型
- Spring中的九种设计模式
- Magix.Cache介绍
- webmin虚拟服务器创建,如何在服务器上安装配置Webmin
- Linux内核如何加载固件,驱动是如何工作的_Linux设备驱动的固件加载详解
- HTML既粗体又斜体,HTML粗体,斜体,预格式化等基操
- python抓包之后、如何解析包_python如何抓包