Question

There are 100 doors in a row that are all initially closed.

You make 100 passes by the doors.

The first time through, visit every door and toggle the door (if the door is closed,open it;if it is open,close it).

The second time, only visit every 2nd door (door #2, #4, #6, ...),and toggle it.

The third time, visit every 3rd door (door #3, #6, #9, ...), etc,until you only visit the 100th door.

Task

Answer the question: what state are the doors in after the last pass? Which are open, which are closed?

先把问题缩小: 10道门关着,按以上方式遍历这些门10次。 最后很明显,第一道们肯定是开着的;第二、第三是关着的! X道门的开关次数跟X的约数有关,如果X有偶数个约数则门最终的状态是关着的,否则为开着的。

问题现在变成: 1 到 100 之间公约数个数为奇数的数字是?

[i * i for i in range(1, int(math.sqrt(100)) + 1)] // [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Java Solution

public class Doors
{
public static void main(String[] args)
{
for(int i=0;i<10;i++)
System.out.println("Door #"+(i + 1)*(i + 1) +" is open.");
}
}

100 doors的更多相关文章

  1. 100 Door Puzzle

    问题重述: There are 100 doors in a long hallway. They are all closed. The first time you walk by each do ...

  2. 欧拉回路-Door Man 分类: 图论 POJ 2015-08-06 10:07 4人阅读 评论(0) 收藏

    Door Man Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2476 Accepted: 1001 Description ...

  3. POJ 1300 Door Man - from lanshui_Yang

    Description You are a butler in a large mansion. This mansion has so many rooms that they are merely ...

  4. POJ1300(欧拉回路)

    Door Man Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2139   Accepted: 858 Descripti ...

  5. POJ 1300.Door Man 欧拉通路

    Door Man Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2596   Accepted: 1046 Descript ...

  6. POJ1300Door Man(欧拉回路)

                                                               Door Man Time Limit: 1000MS   Memory Limi ...

  7. POJ1300 Door Man —— 欧拉回路(无向图)

    题目链接:http://poj.org/problem?id=1300 Door Man Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

  8. [欧拉回路] poj 1300 Door Man

    题目链接: http://poj.org/problem?id=1300 Door Man Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  9. POJ 1300 Door Man(欧拉通路)

    题目描写叙述: 你是一座大庄园的管家. 庄园有非常多房间,编号为 0.1.2.3..... 你的主人是一个心不在 焉的人,常常沿着走廊任意地把房间的门打开.多年来,你掌握了一个诀窍:沿着一个通道,穿 ...

随机推荐

  1. ImageView的src和background的区别

    参考资料: http://blog.csdn.net/dalleny/article/details/14048375 http://www.android100.org/html/201508/27 ...

  2. 解决TestNG报java.net.SocketException

    在运行TestNG时一直给我提示报“java.net.ScketException”问题, 网上查了下这个问题是要有网络写入的一些操作才会导致,我的程序也没有网络写入,因为我是使用的selenium+ ...

  3. 极其简单的使用基于gulp和sass前端工作流

    简单的记录自己如何在实际工作中使用gulp和sass的.我的原则是,小而美! gulp与sass介绍 gulp 什么是gulp?和Grunt一样,是一种任务管理工具:和Grunt又不一样,gulp是一 ...

  4. 浅谈call和apply的联系&区别&应用匹配

    call和apply的联系和区别在之前查过资料了解了一番,昨天晚上睡不着觉忽然想到了这个问题,发现对于他们的联系和区别理解的还是很模糊.看来还是欠缺整理,知识没有连贯起来.反思一二,详情如下: 1作用 ...

  5. sql中的case when语句

    1.在where子句中: CREATE TABLE `hello`.`sometbl` ( `id` INT NOT NULL AUTO_INCREMENT , `a` VARCHAR(45) NUL ...

  6. iOS开发——打包ipa

    首先,保证设备证书和配置文件的正确,Xcode上登陆好自己公司的账号Apple ID 1.选中运行模拟器的位置为硬件设备 2.点击导航栏上的[Product]——[Archive]后编译后弹出如下界面 ...

  7. easyui扩展-日期范围选择.

    参考: http://www.5imvc.com/Rep https://github.com/dangrossman/bootstrap-daterangepicker * 特性: * (1)基本功 ...

  8. WaitForSingleObject用法

    对应函数 编辑 VC声明 DWORD WaitForSingleObject( HANDLE hHandle, DWORD dwMilliseconds );   参数 编辑 hHandle[in]对 ...

  9. html的3要素

    在HTML标记语言中可以将每个网页源码分成3部分: 1.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" &q ...

  10. sql server返回插入数据表的id,和插入时间

    假设要插入数据的数据表结构如下