Sherlock and Squares

//Link

  https://www.hackerrank.com/challenges/sherlock-and-squares

 1 from math import sqrt # 用什么,引什么,减少浪费和错误可能性
 2
 3
 4 def main():
 5     t = int(raw_input())
 6     for _ in range(t):
 7         squares = 0
 8         a, b = map(int, raw_input().strip().split(‘ ‘))
 9         temp = int(sqrt(a)) # 设置temp的起始判断点
10         while temp ** 2 <= b: # 卡住上下边界
11             if temp ** 2 >= a:
12                 squares += 1
13             temp += 1
14
15         print squares
16
17 main()

学习

  抽象到本质后,开始反向思维

  反向思维:

    正向思维的话:

      每个数都需要开方,要是注意到Input的要求,会发现这个量可是相当大的

    反向:

      用a开方上沿儿的边界值开始,平方后测试值在不在[a,b]范围内,因为平方的上升速度是相当快的

时间: 2024-10-06 17:36:14

Sherlock and Squares的相关文章

USACO 1.2 Palindromic Squares

Palindromic SquaresRob Kolstad Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that

Partial least squares regression(偏最小二乘法回归)

偏最小二乘法(PLS)是近年来发展起来的一种新的多元统计分析 http://en.wikipedia.org/wiki/Partial_least_squares_regression Partial least squares regression(偏最小二乘法回归),布布扣,bubuko.com

HDU 1264 Counting Squares(模拟)

题目链接 Problem Description Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) that specify the opposite corners of a rectangle. All coordinates will be integers in the range 0 to 100. For example, the lin

Codeforces Round #337 (Div. 2) B. Vika and Squares 水题

B. Vika and Squares Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of s

Project Euler 98:Anagramic squares 重排平方数

Anagramic squares By replacing each of the letters in the word CARE with 1, 2, 9, and 6 respectively, we form a square number: 1296 = 362. What is remarkable is that, by using the same digital substitutions, the anagram, RACE, also forms a square num

SuperVision - Sherlock 通用界面程序

SuperVision Sherlock 人机界面快速开发(配置)平台 不是软件工程师也能整出专业的 HMI.

uva201 Squares

 Squares  A children's board game consists of a square array of dots that contains lines connecting some of the pairs of adjacent dots. One part of the game requires that the players count the number of squares of certain sizes that are formed by the

USACO 6.5 All Latin Squares

All Latin Squares A square arrangement of numbers 1 2 3 4 5 2 1 4 5 3 3 4 5 1 2 4 5 2 3 1 5 3 1 2 4 is a 5 x 5 Latin Square because each whole number from 1 to 5 appears once and only once in each row and column. Write a program that will compute the

Dalsa Sherlock 直连千兆网相机(通用驱动)

支持 Sherlock 7.1.7.2,用于千兆网相机与 Sherlock 的连接. 可适用于很多厂商的相机,如:巴斯勒(Basler),JAI,堡盟相机(Baumer),灰点相机(Point Grey)...等等 1. 支持多个相机连接: 2. 支持黑白和彩色相机的单独或并存连接: 3. 支持采集图像buffer(防漏检),可设置队列的大小,是否启用: 4. 可根据相机序号(sn)进行排序(0,1,2-): 5. 可配置硬件触发.连续触发和初始化时相机的各个参数: 6. 可在sherlock中