题目大意:原题链接

给定数组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(快速幂+三分法)的更多相关文章

  1. CDOJ 1048 Bob's vector 三分

    Bob's vector 题目连接: http://acm.uestc.edu.cn/#/problem/show/1048 Description Bob has a vector with mm ...

  2. 计蒜客 ACM训练联盟周赛 第一场 Alice和Bob的Nim游戏 矩阵快速幂

    题目描述 众所周知,Alice和Bob非常喜欢博弈,而且Alice永远是先手,Bob永远是后手. Alice和Bob面前有3堆石子,Alice和Bob每次轮流拿某堆石子中的若干个石子(不可以是0个), ...

  3. CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂

    772002画马尾 题目连接: http://acm.uestc.edu.cn/#/problem/show/1280 Description 众所周知772002很喜欢马尾,所以他决定画几幅马尾送给 ...

  4. CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂 中二版

    "问题:众所周知772002很喜欢马尾,所以他决定画几幅马尾送给他的女朋友. 772002会画m种马尾,772002还有n张纸,n张纸分别编号1到n,每张纸上只能画一种马尾. 然而77200 ...

  5. HDU4965 Fast Matrix Calculation —— 矩阵乘法、快速幂

    题目链接:https://vjudge.net/problem/HDU-4965 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Othe ...

  6. 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 ...

  7. Hdu 4965(矩阵快速幂)

    题目链接 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

  8. 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 输 ...

  9. 1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)

    http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会 ...

随机推荐

  1. 京东云擎提供了免费的wordpress一键安装功能了

    1. 京东云擎(http://jae.jd.com)提供了免费的个人博客WordPress一键安装功能了,如下图,给开发者分享福利! 免费的应用,提供了源码,提供了数据库: 我之前把文章发到首页,遭到 ...

  2. Effective C++ —— 让自己习惯C++(一)

    条款01 : 视C++为一个语言联邦 C++ == C(C基本语法) + Object-Oriented C++(类,封装,继承,多态……) + Template C++(泛型编程) + STL(容器 ...

  3. Set集合遍历方式

    for(String str : set) { System.out.println(str); } for (Iterator iter = set.iterator(); iter.hasNext ...

  4. Runtime应用(二)使用对象关联为分类增加属性(每个对象的属性互不干扰)

    一.对象的关联方法有 1. void objc_setAssociatedObject(id object, const void *key, id value,objc_AssociationPol ...

  5. 【linux】Centos下登陆mysql报错#1045 - Access denied for user 'root'@'localhost' (using password: NO)

    创建mysql  远程链接 grant all privileges on *.* to 'test'@"%" identified by "test666 with g ...

  6. call和apply方法

    /* * @ call和apply方法 * @ 当一个object没有某个方法,但是其他的有,我们可以借助call或apply用其它对象的方法来操作. * @ (有方法的)对象.call(" ...

  7. 【MySQL案例】error.log的Warning:If a crash happens thisconfiguration does not guarantee that the relay lo(转)

    标签: 1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be c ...

  8. Charles(网络封包分析工具)

    一.what Charles工具是通过将自己设置成系统的网络访问代理服务器,使得所有的网络访问请求都通过它来完成,从而实现了网络封包的截取和分析. 它能实现以下 支持SSL代理:截取分析SSL的请求. ...

  9. MYSQL创建数据表!

    几个常见的建表原则: a,表都加前缀b,所有的字段选择最小的数据类型,如id可以使用mediumint比INT节省25%的空间c,尽量所有的字段都设置为NOT NULL的,这样能让速度更快d,为合适的 ...

  10. JavaMVC框架之SpringMVC

    欢迎查看Java开发之上帝之眼系列教程,如果您正在为Java后端庞大的体系所困扰,如果您正在为各种繁出不穷的技术和各种框架所迷茫,那么本系列文章将带您窥探Java庞大的体系.本系列教程希望您能站在上帝 ...