`
kellychan
  • 浏览: 2815 次
  • 性别: Icon_minigender_2
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

pop 1218 THE DRUNK JAILER java版

    博客分类:
  • poj
阅读更多
原题如下:
THE DRUNK JAILER
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 20311 Accepted: 12822
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.
Sample Input

2
5
100
Sample Output

2
10

解法:求1-n之间有多少个平方数

我的java代码:

import java.util.Scanner;

public class Main{
	public static void main(String args[])
	{
		Scanner cin = new Scanner(System.in);
		int numberNum = cin.nextInt();
		int numbers[] = new int[numberNum];
		for(int i = 0; i < numberNum; i++){
			numbers[i] = cin.nextInt();
		}
		
		for(int k = 0; k < numberNum; k++)
		{
			int unlockedNum = 0;
			
			for(int i = 1; i <= numbers[k]; i++)
			{
				for(int j = 1; j < numbers[k]; j++)
				{
					if(i == j*j)
					{ //if i is the square of j,then the door at the place is unlocked
						unlockedNum++;
						break;
					}
				}
			}
			System.out.println(unlockedNum);
		}
	
	}
	
}


望同志们多多指教!
分享到:
评论
2 楼 softliumin 2013-07-17  
你加入不是模拟过程,而是通过里面的规律开结题,那么可以这么写:
Scanner cin = new Scanner(System.in);

int n = cin.nextInt();
for (int i = 0; i < n; i++)
{
System.out.println((int) Math.sqrt((double) cin.nextInt())  );
}
cin.close();
1 楼 softliumin 2013-07-17  
这个代码,我看了好久,才看懂······

相关推荐

    Drunk

    Drunk

    The Drunk User-crx插件

    语言:English (United States) 用醉酒的眼睛看一下您的网站。 用户应该能够查看页面并立即识别出他应该走的路。 因此,这是一个问题:用户是否可以浏览您的转化渠道而无法阅读您网站上的单个单词?...

    Too Damn Drunk

    Too Damn Drunk

    小学英语英语故事幽默故事醉酒Drunk

    小学英语英语故事幽默故事醉酒Drunk

    喝醉了的用户「The Drunk User」-crx插件

    看一看你的网站,有醉汉的眼睛。 用户应该能够查看页面并立即识别出他应该走的路。 因此,这是一个问题:用户是否可以浏览您的转化渠道而无法阅读您网站上的单个单词? 在大多数情况下,不会。 ...

    Ruby-不gitcommit当你drunk时

    不git commit当你drunk时

    cpp-IVRE又名DRUNK是一款开源的网络侦查框架工具

    IVRE(又名DRUNK)是一款开源的网络侦查框架工具,IVRE使用Nmap、Zmap进行主动网络探测、使用Bro、P0f等进行网络流量被动分析,探测结果存入数据库中,方便数据的查询、分类汇总统计。

    ZJU_ACM_All_Anwer 搞编程的都知道的浙江大学A 题库.本书 集了所有经 Z 题解集,集合并附 Mathimaticsumerical algorithms 数值算法

    1350 The Drunk Jailer 简单题 1352 Number Base Conversion 简单题 1353 Unimodal Palindromic Decompositions 规模不大,所以是简单题…… 1354 Extended Lights Out 简单题 1362 Game Prediction 简单题 ...

    浙江大学ACM题解/ZJU 题型分类

    1350 The Drunk Jailer 简单题 1352 Number Base Conversion 简单题 1353 Unimodal Palindromic Decompositions 规模不大,所以是简单题…… 1354 Extended Lights Out 简单题 1362 Game Prediction 简单题 ...

    drunk-timer:惊人的计时器 API

    醉酒的计时器 惊人的计时器 API 演示:安装npm: npm install drunk-timer凉亭: bower install drunk-timer下载: 应用程序接口config(opts={}): void setInterval(callback: function, delay: number): number ...

    drunk_detection

    drunk_detection

    drunk-generator

    drunk-generator 生成drunk标准目录结构 mymodule ├─index....

    Drunk-O-Clock:Pebble移植到Android Wear

    醉钟这是移植到Android Wear的Pebble版本的Drunk O'Clock。

    Bupa 数据集

    1. Title: BUPA liver disorders 2. Source information: -- Creators: BUPA Medical Research Ltd. ... drunk per day 7. selector field used to split data into two sets 8. Missing values: none

    C52-drunk.zip_MQ3_声光报警_酒精传感器_酒精浓度检测_防酒后驾驶

    一种基于单片机的防酒后驾驶自动控制系统,应用于酒精浓度的检测。该系统由酒精传感器、AD0832转换器、89S51单片机控制器、声光报警、LED显示以及继电器等构成。其设计方案基于AT89S51单片机,MQ3酒精浓度传感器。

    Drunk-Man-Game

    醉汉游戏 使用rand()的简单方法。 在这里,用户需要输入任何字母,这将被视为醉酒的人。 醉酒的人会前后走动,具体取决于随机函数决定的步数。 没有偏见。 这些步骤已执行了数千次,最后我们得到了结果。...

    Drunk Test-crx插件

    语言:English (United States) 预制件在给定站点上的“用户是醉酒”测试 drunks有模糊的视觉。 为用户提供专注的一个重要措施,无论是为您的服务注册还是购买烤肉串。 您仍然应该能够理解主要的行动和地区。

    camera filter pack v4.1.0

    – Improve Drunk parameters ( Distortion, Color, Wave and more ) – Improve TV Noise Parameters – Add Movie Noise – Improve Old Movie 2 Parameters – Improve TV 50′ and TV 80′ 3.0.1 – Fix Lut ...

    Drunk_Driving:D3 多折线图

    网络应用程序模板简单 带有 jQ​​uery 和 Bootstrap 的简单 Web 应用程序模板。 | Mizzou 工作坊 - 2014 年 10 月

    sleep-drunk:达特茅斯 CS69169 最终项目

    睡醉达特茅斯 CS69/169 最终项目您是否知道连续 24 小时保持清醒会导致与喝 4-5 杯酒精饮料相同的认知障碍? 我们在达特茅斯学院计算机科学 69/169 (MobileHealth) 的最后一个项目中制作的这个 android 应用程序将...

Global site tag (gtag.js) - Google Analytics