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 ...
随机推荐
- C++ 的多重继承
不能够从对象访问基类的公开方法,真悲剧!只能在类里面提供公共函数! void Mentor::GetInfo(){ cout<<endl<<name<<endl&l ...
- Spring MVC URL传参
Spring MVC 学习 之 - URL参数传递 在学习 Spring Mvc 过程中,有必要来先了解几个关键参数: @Controller: 在类上注解,则此类将编程一个控制器,在项目启 ...
- Manage Spring Boot Logs with Elasticsearch, Logstash and Kibana
下载地址:https://www.elastic.co/downloads When time comes to deploy a new project, one often overlooked ...
- Maven, IntellJ Idea 配置注意点
1. Maven要自己安装一个: 2. Maven设置中,settings.xml和repository地址都配置成自己: 3. Enable Auto import 4. 找不到jar文件时,自己的 ...
- Jsvc安装,配置 常规用户使用tomcat的80端口
Jsvc安装 一.下载安装包,地址如下: http://commons.apache.org/proper/commonsdaemon/download_daemon.cgi 二.安装步骤,参考链接 ...
- 【转】Android ListView长按事件触发点击事件
原文网址:http://blog.csdn.net/twlkyao/article/details/17301609 算法在实现ListView的onItemLongClickListener的时候, ...
- 【转】Win7与Ubuntu 14.04双系统修改启动项顺序
原文网址:http://blog.sina.com.cn/s/blog_b381a98e0102v1gy.html 一.Ubuntu14.04采用默认安装方式的情况 采用默认安装方式,在win7下安装 ...
- Linux调试工具strace和gdb常用命令小结
strace和gdb是Linux环境下的两个常用调试工具,这里是个人在使用过程中对这两个工具常用参数的总结,留作日后查看使用. strace调试工具 strace工具用于跟踪进程执行时的系统调用和所接 ...
- poj1185:炮兵阵地(状压dp)
也算是比较基础的状压dp了,跟做过的第二道比较又稍微复杂了一点 需要记录之前两行的状态.. 统计结果也稍有不同 另外还学习了一个得到一个整数二进制位 1 的个数的位运算方法 详见代码: #includ ...
- hdu2768-Cat vs. Dog:图论:二分匹配
Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...