URAL 1948 H - The Robot on the Line 二分 + 数学
http://acm.hust.edu.cn/vjudge/contest/126149#problem/H
给定一条二次函数 f (x) = a * x * x + b * x + c
求一个最小的k,使得f(x) + f(x + 1) + f(x + 2) ..... + f(x + k - 1) 不等于 0 恒成立。
首先把参数统一写成 x + t这样的形式,然后带入去
化简有:a*x*x + (2*a*t+b)*x + a*t*t+b*t+c //现在的t是从0--k-1
列出k个式子,求和(简单的数列求和)。然后就得到一条关于x的二次函数,用判别式判断即可。
为什么能二分?
因为单调。化简后可以看到B*B - 4*A*C。k越大,<0就越成立。因为4*A*C有k的项且指数都比较高。所以这个判断是单调的。
则二分即可。
数字很大 啊。用double居然没爆。应该用到了1e100。double犀利啊
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
LL a, b, c;
bool check (LL t) {
double k = (double)t;
double B = (b + * a * (k - ) + b) * k / 2.0;
double C = a * (k - ) * (k) * ( * (k - ) + ) / + (k - ) * k / * b + k * c;
double A = k * a;
// cout << B << " " << C << " " << A << endl;
return B * B < * A * C;
}
void work () {
cin >> a >> b >> c;
// cout << a << " " << b << " " << c << endl;
LL begin = ;
LL end = 1e18;
// cout << check (9) << endl;
while (begin <= end) {
LL mid = (begin + end) >> ;
// cout << mid << endl;
if (check (mid)) { //mid是满足条件的,就是方程无解的
// cout << " ***" << endl;
end = mid - ;
} else {
begin = mid + ;
}
}
if (begin > 1e18) {
printf ("Infinity\n");
} else {
cout << begin << endl;
}
return ;
} int main () {
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
cin >> t;
while (t--) work ();
return ;
}
URAL 1948 H - The Robot on the Line 二分 + 数学的更多相关文章
- CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 二分+拓扑排序
D. Robot Rapping Results Report 题目连接: http://www.codeforces.com/contest/655/problem/D Description Wh ...
- URAL - 1486 Equal Squares 二维哈希+二分
During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued about who o ...
- codeforces 251A Points on Line(二分or单调队列)
Description Little Petya likes points a lot. Recently his mom has presented him n points lying on th ...
- H - Prince and Princess - HDU 4685(二分匹配+强连通分量)
题意:有N个王子M个公主,王子喜欢一些公主,而且只能是王子喜欢的人,他们才可以结婚,现在让他们尽可能多的结婚的前提下找出来每个王子都可以和谁结婚. 分析:先求出来他们的最大匹配,因为给的数据未必是完备 ...
- CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序
题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...
- Codeforces H. Prime Gift(折半枚举二分)
题目描述: Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard ...
- 2019牛客暑期多校训练营(第九场)H Cutting Bamboos(主席树+二分)
题意:n个竹子,有高度,q次询问,询问之间是独立的,每次查询输入l,r,x,y代表砍区间[l,r]]内的竹子砍y次,最后一次要砍成0,每次砍掉的总长度相同,问第x次砍的高度是多少. 既然每次要求砍掉的 ...
- 2014 Super Training #6 H Edward's Cola Plan --排序+二分
原题: ZOJ 3676 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3676 题意:给每个朋友一瓶可乐,可乐有普通和高 ...
- codeforces 645 D. Robot Rapping Results Report 二分+拓扑排序
题目链接 我们可以发现, 这是一个很明显的二分+拓扑排序.... 如何判断根据当前的点, 是否能构造出来一个唯一的拓扑序列呢. 如果有的点没有出现, 那么一定不满足. 如果在加进队列的时候, 同时加了 ...
随机推荐
- poj3414Pots(倒水BFS)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13231 Accepted: 5553 Special J ...
- HDOJ2141(map在二分搜索中的应用)
#include<iostream> #include<cstdio> #include<map> #include<algorithm> using ...
- 在Golang中使用C语言代码实例
转自:http://www.jb51.net/article/56720.htm cgo 使得在 Golang 中可以使用 C 代码. Hello World 为了有一个较为直观的了解,我们来看一个简 ...
- Spring boot 学习一:认识Spring boot
什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...
- [bzoj3670] [NOI2014] [lg2375] 动物园
nxt数组为KMP的next数组num[i]储存了i前面可以匹配的串的个数.先在KMP求nxt中顺便求出num最后再找到对于i的最大的前后缀不重叠的可匹配的j,ans*=(num[j]+1)%1000 ...
- NW.js将网站打包成桌面应用
需求:已有一个网站,因为浏览器兼容性等问题,想自己封装一个浏览器,打开时固定打开这个网站,通过这样的封装,将网站变成桌面应用程序. 1. 下载并安装NW.js的最新稳定版本(NW.js) 2. 创建一 ...
- Spring MVC Flash Attribute 的讲解与使用示例
转自:https://www.oschina.net/translate/spring-mvc-flash-attribute-example Spring MVC 3.1版本加了一个很有用的特性,F ...
- JS取得绝对路径
在项目中,我们经常要得到项目的绝对路径,方便我们上传下载文件,JS为我们提供了方法,虽说要迂回一下.代码如下: function getRealPath(){ //获取当前网址,如: h ...
- JAVA中判断char是否是中文的几种方法
1.方法一 char c = 'a'; if((c >= 0x4e00)&&(c <= 0x9fbb)) { System.out.println("是中文&qu ...
- 以后尽量不用cin、cout啦
cout输出有问题(对于double,不同OJ处理的结果不一样),cin读入机制较scanf繁琐.慢!!!!!!!!