POJ 3175 Finding Bovine Roots (暴力求解)
2024-10-13 13:04:44
题意:给定一串数字,问你这是一个数字开方根得到的前几位,问你是哪个数字。析:如果 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;
}
最新文章
- visual studio 2013 中配置OpenCV2.4.13 姿势
- 【2016-11-3】【坚持学习】【Day18】【Oracle 数据类型 与C#映射关系】
- thinkphp 3.23语言包加载
- Adding a Controller
- Python学习基本
- What does ";Rxlch"; mean in ENCODE?
- css强制换行和超出隐藏实现
- php中getimagesize函数的用法
- 使用hexo创建github博客
- [LeetCode][Python]Container With Most Water
- java运行脚本语言demo
- .bat文件设置IP、DNS
- python学习笔记之运算符
- 【译】索引进阶(七):SQL SERVER中的过滤索引
- 移动端添加横向滚动条&;隐藏
- 3分钟看完Java 8——史上最强Java 8新特性总结之第二篇 Stream API
- C语言中volatile的作用和使用方法
- Java语法基础课 原码 反码 补码
- UVA 12307 Smallest Enclosing Rectangle
- 错误代码0x00000001,好多软件连不了网,求助~(WIN7/win8/win9/win10)