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. 使用C#动态生成Word文档/Excel文档的程序测试通过后,部署到IIS服务器上,不能正常使用的问题解决方案

    使用C#动态生成Word文档/Excel文档的程序功能调试.测试通过后,部署到服务器上,不能正常使用的问题解决方案: 原因: 可能asp.net程序或iis访问excel组件时权限不够(Ps:Syst ...

  2. android手机中图片的拖拉及浏览功能

    配置文件 activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/andro ...

  3. Android之进度条1

    第一种方法(比较简单): package com.example.dialogdemo; import java.util.Random; import android.app.Activity; i ...

  4. Cocos2d-x数据持久化-修改数据

    修改数据时,涉及的SQL语句有insert.update和delete语句,这3个SQL语句都可以带参数.修改数据的具体步骤如下所示.(1) 使用sqlite3_open函数打开数据库.(2) 使用s ...

  5. 常用DOM笔记

    1,获取元素方法: (1),获取单个,返回一个元素 element.getElementById()//最快,实时 element.querySelector() (2)获取多个,返回一组 eleme ...

  6. [Guava学习笔记]Collections: 集合工具类

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3861431.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  7. Linux 简单字符设备驱动程序 (自顶向下)

    第零章:扯扯淡 特此总结一下写的一个简单字符设备驱动程序的过程,我要强调一下“自顶向下”这个介绍方法,因为我觉得这样更容易让没有接触过设备驱动程序的童鞋更容易理解,“自顶向下”最初从<计算机网络 ...

  8. 离线文档(DocSet)下载地址汇总

    我分享的百度网盘地址,官网下载慢:http://pan.baidu.com/s/1uOBYQ 名称 下载地址 更新时间 IOS 9.2 031-43202-A.dmg 20151209 OS X 10 ...

  9. c#中const与readonly区别

    const 的概念就是一个包含不能修改的值的变量.常数表达式是在编译时可被完全计算的表达式.因此不能从一个变量中提取的值来初始化常量.如果 const int a = b+1;b是一个变量,显然不能再 ...

  10. NodeJS + Socket.io搭建聊天服务器

    第一步:安装node git clone https://github.com/joyent/node.git cd node git checkout v0.10.33-release ./conf ...