题意:给定一串数字,问你这是一个数字开方根得到的前几位,问你是哪个数字。析:如果 x.123... 这个数字的平方是一个整数的话,那必然sqr(x.124) > ceil(sqr(x.123)) [sqr = 求平方, ceil = 向上取整
所以,就可以从小到大枚举它的整数部分 x ,遇到第一个满足结果的 x,就是答案了。

开始时,我从1开始暴力超时了。。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-11;
const int maxn = 1000 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0}; int main(){
int n;
double x;
scanf("%d", &n);
scanf("%lf", &x); double t = 1.0;
for(int i = 0; i < n; ++i)
t /= 10.0; x *= t;
for(int i = 1; ;++i){
double y = (LL)((x+i) * (i+x)) + 1;
double yy = (x+t+i) * (x+t+i); if(yy > y){
printf("%lld\n", (LL)(y));
break;
}
} return 0;
}

最新文章

  1. visual studio 2013 中配置OpenCV2.4.13 姿势
  2. 【2016-11-3】【坚持学习】【Day18】【Oracle 数据类型 与C#映射关系】
  3. thinkphp 3.23语言包加载
  4. Adding a Controller
  5. Python学习基本
  6. What does &quot;Rxlch&quot; mean in ENCODE?
  7. css强制换行和超出隐藏实现
  8. php中getimagesize函数的用法
  9. 使用hexo创建github博客
  10. [LeetCode][Python]Container With Most Water
  11. java运行脚本语言demo
  12. .bat文件设置IP、DNS
  13. python学习笔记之运算符
  14. 【译】索引进阶(七):SQL SERVER中的过滤索引
  15. 移动端添加横向滚动条&amp;隐藏
  16. 3分钟看完Java 8——史上最强Java 8新特性总结之第二篇 Stream API
  17. C语言中volatile的作用和使用方法
  18. Java语法基础课 原码 反码 补码
  19. UVA 12307 Smallest Enclosing Rectangle
  20. 错误代码0x00000001,好多软件连不了网,求助~(WIN7/win8/win9/win10)

热门文章

  1. 每个极客都应该知道的Linux技巧
  2. UVa 10498 Happiness! (线性规划)
  3. WM8962 HPOUT 信号强度 时间周期
  4. mysql 数据库常用命令总结
  5. JavaScript对象 + Browser 对象 + HTML DOM 对象
  6. Linux VPS 基本命令
  7. linux下安装虚拟机qemu kqemu
  8. 【转】iOS开发-Protocol协议及委托代理(Delegate)传值
  9. git常用知识整理
  10. 支持多种浏览器的纯css下拉菜单