zoukankan      html  css  js  c++  java
  • CDOJ 1048 Bob's vector 三分

    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
    ",i);
                return 0;
            }
        }
    }
  • 相关阅读:
    Oracle操作步骤
    Jquery 使用Ajax获取后台返回的Json数据后,页面处理
    Win10 CMD中文乱码解决
    GIT库中禁止追踪文件变化的两种方式
    Google Chrome升级到81.x之后http请求自动转https的解决方案
    【rabbitmq】Queueingconsumer被废止后老代码如何做的解决方案
    使用线程池测试cpu的并发计算能力
    springmvc线程安全问题
    zookeeper初体验之关于解决quartz重复执行任务的一种思路
    restful风格的webservice开发之概念准备篇
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5327955.html
Copyright © 2011-2022 走看看