hdu4430Yukari's Birthday(二分)
去年长春最简单一题 二分啊 错了好多遍 有个大坑 是个圆心处的1 可选可不选
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define LL __int64
LL s;
int main()
{
int i,j;
while(scanf("%I64d",&s)!=EOF)
{
LL maxz = s-,m1 = ,m2 = s-;
for(i = ; i <= ; i++)
{
LL low = ,high = s,m;
double ty = ,ts=;
while(low<=high)
{
m = (low+high)/;
ts = ,ty=;
for(j = ; j <= i ; j++)
{
ts+=ty;
ty*=m;
if(ts>s) break;
}
if(ts>s)
high = m-;
else if(ts<s)
low = m+;
else break;
}
if(s==ts&&maxz>i*m)
{
maxz = i*m;
m1 = i;
m2 = m;
}
low = ,high = s,ts=,ty=;
while(low<=high)
{
m = (low+high)/;
ts = ,ty=m;
for(j = ; j <= i ; j++)
{
ts+=ty;
ty*=m;
if(ts>s) break;
}
if(ts>s)
high = m-;
else if(ts<s)
low = m+;
else break;
}
if(s==ts&&maxz>i*m)
{
maxz = i*m;
m1 = i;
m2 = m;
}
}
printf("%I64d %I64d\n",m1,m2);
}
return ;
}
hdu4430Yukari's Birthday(二分)的更多相关文章
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]
2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 3352 Solved: 919[Submit][Stat ...
- 整体二分QAQ
POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...
- [bzoj2653][middle] (二分 + 主席树)
Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...
- [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二
Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...
- [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值
Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...
- jvascript 顺序查找和二分查找法
第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...
- BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流
1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...
- BZOJ 3110 [Zjoi2013]K大数查询 ——整体二分
[题目分析] 整体二分显而易见. 自己YY了一下用树状数组区间修改,区间查询的操作. 又因为一个字母调了一下午. 貌似树状数组并不需要清空,可以用一个指针来维护,可以少一个log 懒得写了. [代码] ...
随机推荐
- c++ 继承和组合的区别
.什么是继承 A继承B,说明A是B的一种,并且B的所有行为对A都有意义 eg:A=WOMAN B=HUMAN A=鸵鸟 B=鸟 (不行),因为鸟会飞,但是鸵鸟不会. .什么是组合 若在逻辑上A是B的“ ...
- Spring Mvc 返回机制
转自:http://jianzh5.iteye.com/blog/1909234 Spring Mvc 有如下的几种返回方式: ModelAndView, Model, ModelMap, Map, ...
- Detecting diabetic retinopathy in eye images
Detecting diabetic retinopathy in eye images The past almost four months I have been competing in a ...
- PowerDesigner(三)-企业架构模型(转)
企业架构模型(Enterprise Architecture Model,EAM)是PowerDesigner 15新增的功能,它能够以图形的方式展现企业架构,从而取代文字描述:以偏向非技术性的表达方 ...
- PHP 性能分析第一篇: Xhprof & Xhgui 介绍
[前言]这是国外知名博主 Davey Shafik所撰写的 PHP 应用性能分析系列的第一篇,阅读第二篇可深入了解 xhgui,第三篇则关注于性能调优实践. 什么是性能分析? 性能分析是衡量应用程序在 ...
- Nginx搭建flv视频点播服务器
Nginx搭建flv视频点播服务器 前一段时间使用Nginx搭建的多媒体服务器只能在缓冲过的时间区域内拖放, 而不能拖放到未缓冲的地方. 这就带来了一个问题: 如果视频限速的速率很小, 那么客户端观看 ...
- ThinkPHP 单字母函数整理
TP所有单独的函数,除了两个用来生成项目的buildAppDir之类的,其余都在框架目录/Common/functions.php这个文件里. A函数(基本是Action的简写) A函数是用来实例化我 ...
- ExtJs之Ext.util.MixedCollection
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- Codeforces Round #336 (Div. 2)C. Chain Reaction DP
C. Chain Reaction There are n beacons located at distinct positions on a number line. The i-th bea ...
- hdu 1526(最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1526 思路:floyd求传递闭包,然后就是最大匹配了,不过一开始输入没看清,被坑了将近2个小时. #i ...