Bob's vector

题目连接:

http://acm.uestc.edu.cn/#/problem/show/1048

Description

Bob has a vector with mm elements, called vector BB. Now Alice gives him a vector XX with nn elements.

Then he gets a new vector AA, in which Ai=(B1×Xi+B2×X2i⋯+Bm−1×Xm−1i+Bm×Xmi)Ai=(B1×Xi+B2×Xi2⋯+Bm−1×Xim−1+Bm×Xim) mod 10000000071000000007.

Now Alice wants to find a peak position in vector AA, and a peak position is a position whose value is greater than both of its neighbors. You may assume that A0=−∞,An+1=−∞A0=−∞,An+1=−∞.

As is known to everyone of you, Bob loves Alice very much. Could you tell Bob the answer to help Bob leave a good impression on Alice.

Input

The frist line contains 22 integers n,mn,m, indicating the size of vector XX and the size of vector BB.

The second line contains nn integers Xi(0≤Xi≤1000000000)Xi(0≤Xi≤1000000000), indicating the element in the vector XX.

The last line contains mm integers Bi(0≤Bi≤1000000000)Bi(0≤Bi≤1000000000), indicating the element in the vector BB.

It is guaranteed that 1≤n≤500000,1≤m≤100001≤n≤500000,1≤m≤10000, and Ai≠Ai+1(1≤i<n)Ai≠Ai+1(1≤i<n) .

Output

Print a single integer, which denotes a peak position. If there are multiple solutions, you may print any of them.

Sample Input

3 2

2 1 3

1 1

Sample Output

1

Hint

题意

给你一个计算ai的方法

假设f(i) = ai

让你求这个函数的峰值在哪儿。

题解:

肯定不能暴力算出所有ai嘛

这个就像爬山算法一样,一直往高处爬就好了,于是瞎逼三分就完了……

不过这道题数据太水了,怎么写怎么过……

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+7;
const int mod = 1e9+7;
int n,m;
long long x[maxn],b[maxn];
long long quickpow(long long m,long long n,long long k)//返回m^n%k
{
long long b = 1;
while (n > 0)
{
if (n & 1)
b = (b*m)%k;
n = n >> 1 ;
m = (m*m)%k;
}
return b;
}
long long get(int p)
{
if(p==0)return -1e9;
if(p==n+1)return -1e9;
long long ans = 0;
for(int i=1;i<=m;i++)
ans = (ans + b[i]*quickpow(x[p],i,mod))%mod;
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%lld",&x[i]);
for(int i=1;i<=m;i++)
scanf("%lld",&b[i]);
int l = 1,r = n;
while(l<r-10)
{
int midl = (l+l+r)/3;
int midr = (l+r+r)/3;
long long p1 = get(midl);
long long p2 = get(midr);
if(p1>p2)r=midr;
else l=midl;
}
for(int i=l;i<=r;i++)
{
if(get(i)>get(i-1)&&get(i+1)<get(i))
{
printf("%d\n",i);
return 0;
}
}
}

CDOJ 1048 Bob's vector 三分的更多相关文章

  1. CDOJ 1048 Bob's vector(快速幂+三分法)

    题目大意:原题链接 给定数组A[i]的计算方法,求出其任意一个极值点 解题思路:求极值点用三分法,一般计算100次足矣,所以三分时上限为100,不过运行时间可能会长一点    用for循环    用w ...

  2. CF 8D Two Friends (三分+二分)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意 :有三个点,p0,p1,p2.有两个人ali ...

  3. hdu3714 三分找最值

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  4. POJ1704 Georgia and Bob

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9771   Accepted: 3220 Description Georg ...

  5. BZOJ 1857 传送带 (三分套三分)

    在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从 ...

  6. STL vector按多字段值排序

    #include <iostream> #include <vector> #include <string> #include <algorithm> ...

  7. poj3301Texas Trip(三分)

    链接 这题还真没看出来长得像三分.. 三分角度,旋转点. 最初找到所有点中最左边.右边.上边.下边的点,正方形边长为上下距离和左右距离的最大值,如图样例中的四个点(蓝色的),初始正方形为红色的正方形. ...

  8. hdu 4268 Alice and Bob

    Alice and Bob Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  9. 三分套三分 --- HDU 3400 Line belt

    Line belt Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3400 Mean: 给出两条平行的线段AB, CD,然后一 ...

随机推荐

  1. 【过滤器】web中过滤器的使用与乱码问题解决

    一.过滤器Filter 1.filter的简介 filter是对客户端访问资源的过滤,符合条件放行,不符合条件不放行,并且可以对目   标资源访问前后进行逻辑处理 2.快速入门 步骤: 1)编写一个过 ...

  2. PHP7+Nginx的配置与安装教程详解

    下面脚本之家小编把PHP7+Nginx的配置与安装教程分享给大家,供大家参考,本文写的不好还请见谅. 系统环境:centos6.5 x64 软件版本:nginx-1.10.0 php-7.0.6 安装 ...

  3. Linux-Load Average解析(转)

    load Average 1.1:什么是Load?什么是Load Average?   Load 就是对计算机干活多少的度量(WikiPedia:the system Load is a measur ...

  4. java中8种数据类型和默认值所占字节数

    java 8种基本数据类型的默认值及所占字节数 通过一段代码来测试一下 8种基本数据类型的默认值 1 package dierge; 2 3 public class Ceshi { 4 int a; ...

  5. NFS挂载报如下错误信息:mount.nfs: Stale NFS file handle解决

    1)用fuser杀掉占用那个目录的进程 linux:~ # fuser -k /home/msgplus/msgplus/remote_dir 2)强制umount linux:~ # umount ...

  6. P3960 列队

    这是NOIP 2017最后一道题 不知道这道题有没有人代码写的和我一样麻烦. Solution 30分暴力 维护每行每列的元素. 每次删除一个元素的时候, 需要修改一行一列 因此复杂度上界\(O(nm ...

  7. JS中firstChild,lastChild,nodeValue属性

    childNodes 在JavaScript中,使用childNodes属性可以返回一个数组,这个数组包含给定元素节点的全体子节点. firstChild firstChild 这句代码等价于 目标元 ...

  8. JMeter -----响应时间设置

    当压力增大会出现connect timeout error. 解决办法:http request default--advance--timeouts 如填写10,表示大于10ms报错.

  9. Firefox 火狐 页面特殊符号乱码解决方法

    这是由于字体问题导致的. 解决方法,参照下图设置,重点是红色标注区域.衬线字体务必选择兼容性最好的,比如思源黑体.宋体.

  10. Good Bye 2015 F - New Year and Cleaning

    F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...