CDOJ 1048 Bob's vector(快速幂+三分法)
题目大意:原题链接
给定数组A[i]的计算方法,求出其任意一个极值点
解题思路:求极值点用三分法,一般计算100次足矣,所以三分时上限为100,不过运行时间可能会长一点
用for循环
用while循环
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+;
int n,m;
long long x[],b[]; long long Quickpow(long long a,long long b)
{
long long res=;
a%=mod;
while(b){
if(b&) res=res*a%mod;
a=a*a%mod;
b/=;
}
return res;
}
long long Get_Ai(int id)
{
if(id==) return -1e9;
if(id==n+) return -1e9;
long long res=;
for(int i=;i<=m;i++)
res=(res+b[i]*Quickpow(x[id],i))%mod;
return res;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%lld",&x[i]);
for(int i=;i<=m;i++)
scanf("%lld",&b[i]);
int l=,r=n;
while(l<r-){//或者for(int i=0;i<100;i++)
int midl=l+(r-l)/;
int midr=r-(r-l)/;
long long p1=Get_Ai(midl);
long long p2=Get_Ai(midr);
if(p1>p2) r=midr;
else l=midl;
}
for(int i=l;i<=r;i++){
if(Get_Ai(i)>Get_Ai(i-)){
if(Get_Ai(i+)<Get_Ai(i)){
printf("%d\n",i);
return ;
}
}
}
}
CDOJ 1048 Bob's vector(快速幂+三分法)的更多相关文章
- CDOJ 1048 Bob's vector 三分
Bob's vector 题目连接: http://acm.uestc.edu.cn/#/problem/show/1048 Description Bob has a vector with mm ...
- 计蒜客 ACM训练联盟周赛 第一场 Alice和Bob的Nim游戏 矩阵快速幂
题目描述 众所周知,Alice和Bob非常喜欢博弈,而且Alice永远是先手,Bob永远是后手. Alice和Bob面前有3堆石子,Alice和Bob每次轮流拿某堆石子中的若干个石子(不可以是0个), ...
- CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂
772002画马尾 题目连接: http://acm.uestc.edu.cn/#/problem/show/1280 Description 众所周知772002很喜欢马尾,所以他决定画几幅马尾送给 ...
- CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂 中二版
"问题:众所周知772002很喜欢马尾,所以他决定画几幅马尾送给他的女朋友. 772002会画m种马尾,772002还有n张纸,n张纸分别编号1到n,每张纸上只能画一种马尾. 然而77200 ...
- HDU4965 Fast Matrix Calculation —— 矩阵乘法、快速幂
题目链接:https://vjudge.net/problem/HDU-4965 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Othe ...
- F - Experienced Endeavour 矩阵快速幂
Alice is given a list of integers by Bob and is asked to generate a new list where each element in t ...
- Hdu 4965(矩阵快速幂)
题目链接 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...
- 51nod 1126 矩阵快速幂 水
有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给出A,B和N,求f(n)的值. Input 输 ...
- 1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会 ...
随机推荐
- 漫谈.Net关键字系列之一Sealed与Final(转)
转自:http://www.cnblogs.com/isline/archive/2010/08/31/1813396.html Sealed与Final修饰符其实并不是一个语言平台的产物,他们有着各 ...
- 【RF库Collections测试】Get From List
Name:Get From ListSource:Collections <test library>Arguments:[ list_ | index ]Returns the valu ...
- long()
long() 用于将一个对象转换为长整数 In [35]: long(') # 将纯数字的字符串转换为长整数 Out[35]: 123L In [36]: long(12.3) # 将浮点数转换为长整 ...
- NUC131演示如何通过PWM触发ADC。
今天我来讲讲PWM触发ADC的例程 /**************************************************************************** * @f ...
- echarts实现柱状图分页展示
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- iOS - UITableView滚动到指定的cell并且选中
UITableView //项目中遇到的 - (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)a ...
- 开源的PaaS方案:在OpenStack上部署CloudFoundry (三)部署BOSH
BOSH是CloudFoundry提供的用来安装部署和升级CloudFoundry的自动化工具,可是说是CloudFoundry的一部分.总体来说,BOSH是Client/Server结构, BOSH ...
- 【BZOJ4099】Trapped in the Haybales Gold STL
[BZOJ4099]Trapped in the Haybales Gold Description Farmer John has received a shipment of N large ha ...
- go http 文件下载
package main import ( "fmt" "net/http" "os" ) func DownFile() { userFi ...
- INSERT高级应用
INSERT INTO departments VALUES (departments_seq.nextval, 'Entertainment', 162, 1400); INSERT INTO em ...