Sherlock and Squares
//Link
https://www.hackerrank.com/challenges/sherlock-and-squares
from math import sqrt # 用什么,引什么,减少浪费和错误可能性 def main():
t = int(raw_input())
for _ in range(t):
squares = 0
a, b = map(int, raw_input().strip().split(' '))
temp = int(sqrt(a)) # 设置temp的起始判断点
while temp ** 2 <= b: # 卡住上下边界
if temp ** 2 >= a:
squares += 1
temp += 1 print squares main()
学习
抽象到本质后,开始反向思维
反向思维:
正向思维的话:
每个数都需要开方,要是注意到Input的要求,会发现这个量可是相当大的
反向:
用a开方上沿儿的边界值开始,平方后测试值在不在[a,b]范围内,因为平方的上升速度是相当快的
Sherlock and Squares的更多相关文章
- [LeetCode] Word Squares 单词平方
Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...
- 卡通图像变形算法(Moving Least Squares)附源码
本文介绍一种利用移动最小二乘法来实现图像变形的方法,该方法由用户指定图像中的控制点,并通过拖拽控制点来驱动图像变形.假设p为原图像中控制点的位置,q为拖拽后控制点的位置,我们利用移动最小二乘法来为原图 ...
- Leetcode: Word Squares && Summary: Another Important Implementation of Trie(Retrieve all the words with a given Prefix)
Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...
- [LintCode] Perfect Squares 完全平方数
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...
- HDU 1264 Counting Squares(线段树求面积的并)
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- RSS(Residual Sum of Squares)的自由度为什么是n-1呢
[转载请注明出处]http://www.cnblogs.com/mashiqi 在回归问题中,偶尔我们会遇到求方差的估计的情况.举了例子,我们常常通过Gaussian分布${\cal N}(\mu , ...
- poj-3739. Special Squares(二维前缀和)
题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. ...
- [CareerCup] 7.5 A Line Cut Two Squares in Half 平均分割两个正方形的直线
7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in ha ...
- POJ 2002 Squares
二分.... Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 14530 Accepted: 5488 Descr ...
随机推荐
- python construct文档
The Basics Fields Fields are the most fundamental unit of construction: they parse (read data from t ...
- Spring AOP 原理
AOP将应用系统分为两部分,核心业务逻辑(Core businessconcerns)及横向的通用逻辑,也就是所谓的方面Crosscutting enterprise concerns,例如,所有大中 ...
- IOS NSURL基本操作-备
NSURL其实就是我们在浏览器上看到的网站地址,这不就是一个字符串么,为什么还要在写一个NSURL呢,主要是因为网站地址的字符串都比较复杂,包括很多请求参数,这样在请求过程中需要解析出来每个部门,所以 ...
- cf D. Queue
http://codeforces.com/contest/353/problem/D #include <cstdio> #include <cstring> #includ ...
- qtpanel
https://github.com/MadFishTheOne/qtpanel https://github.com/xiangzhai/qtpanel
- Verdigris: Qt without moc
https://woboq.com/blog/verdigris-qt-without-moc.html https://github.com/woboq/verdigris
- RazorPad中的ModelProvider
在RazorPad的右侧 我们可以提供模型的结构,Json数据结构体 当提供多个的时候 是Json中的数组 [{ Name: "NI" }, { Name: &qu ...
- Linux & Python 导航目录
< Python学习手册(第4版)>< Python Cookbook(第2版)>中文版.pdf< Python 高级编程>< Python 基础教程 第二版 ...
- JS控制菜单样式切换
$('#subtabs a').each(function (i, ele) { var href = $(ele).attr("href"); if (location.href ...
- Computer Graphics Thinking–texture tiling
Here is one question: how to tile texture? One thing worth to notice: The DirectX and OpenGL stipula ...