题目大意:原题链接

给定数组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. Android:控件布局(相对布局)RelativeLayout(转)

    相对布局常用属性: 子类控件相对子类控件:值是另外一个控件的id android:layout_above----------位于给定DI控件之上android:layout_below ------ ...

  2. Hessain 方法重载

     在相应的配置文件里面加上这句话. <property name="overloadEnable" value="true"></proper ...

  3. mount: block device /dev/cdrom is write-protected, mounting read-only 解决方法

    [root@localhost ~]# mount /dev/cdrom /mnt/cdrom/ mount: block device /dev/sr0 is write-protected, mo ...

  4. linux 提示符>怎样退出

    在linux(Red Hat)字符界面下,不小心输入了上漂号 ’ ,结果命令提示符变成了>,然后在q.exit.ctrl+c.ctrl+z都回不去了,不知道怎么回到#的命令提示符?   表示ct ...

  5. nutch 1.7导入Eclipse

    1.下载Nutch1.7的包 apache-nutch-1.7-src.zip,解压之后应该包括 bin,conf,src等目录 2.将解压之后的 apache-nutch-1.7 文件夹放到ecli ...

  6. 拦截chrome的console.log输出

    console.log = function(){}; 这样 console.log(123) 将不会在输出任何调试信息

  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. 网络费用流-最小k路径覆盖

    多校联赛第一场(hdu4862) Jump Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. HOJ 1936&POJ 2955 Brackets(区间DP)

    Brackets My Tags (Edit) Source : Stanford ACM Programming Contest 2004 Time limit : 1 sec Memory lim ...

  10. Django - CBV、FBV

    一.FBV FBV(function base views) 就是在视图里使用函数处理请求. 在之前django的学习中,我们一直使用的是这种方式. 二.CBV CBV(class base view ...