Locker doors 一个坑爹的问题

Locker doors

 1000(ms)

 65535(kb)

 1100 / 3790

There are n lockers in a hallway numbered sequentially from 1 to n. Initially, all the locker doors are closed. You make n passes by the lockers, each time starting with locker #1. On the ith pass, i = 1, 2, ..., n, you toggle the door of every ith locker: if the door is closed, you open it, if it is open, you close it. For example, after the first pass every door is open; on the second pass you only toggle the even-numbered lockers (#2, #4, ...) so that after the second pass the even doors are closed and the odd ones are opened; the third time through you close the door of locker #3 (opened from the first pass), open the door of locker #6 (closed from the second pass), and so on. After the last pass, which locker doors are open and which are closed? How many of them are open? Your task is write a program to output How many doors are open after the last pass? Assumptions all doors are closed at first.

输入

a positive numbers n, total doors. n<=100000

输出

a positive numbers ,the total of doors opened after the last pass.

样例输入

10

样例输出

3

 

走廊上有n个储物柜,编号从1到n依次排列。最初,所有的储物柜门都是关闭的。你经过储物柜n次,每次从1号储物柜开始。在第i遍时,i = 1,2,…如果门是关着的,你就打开它;如果门是开着的,你就关上它。例如,在第一次通过之后,每扇门都是打开的;在第二关时,你只需要打开偶数的储物柜(#2,#4,…),这样在第二关之后,偶数的门就会关上,奇数的门就会打开;第三次通过你关闭3号储物柜的门(从第一次传球开始),打开6号储物柜的门(从第二次传球开始),以此类推。在最后一次传球后,哪些储物柜的门是开着的,哪些是关着的?有多少是开放的?你的任务是编写一个程序来输出在最后一次通过后打开了多少扇门?假设所有的门一开始都是关闭的。

模拟数据:

 

易得到规律ans=\sqrt{n},其中ans为整型数据,代码如下:

#include<iostream>
#include"cmath"
using namespace std;
int main()
{
    int n;
	cin >> n;
    cout << (int)sqrt(n) << endl;
    return 0;
}

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤月水明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值