UESTC 1048 Bob's vector【煞笔三分】
来源:互联网 发布:鼠标推荐 知乎 编辑:程序博客网 时间:2024/06/05 22:53
Bob's vector
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 262143/262143KB (Java/Others)
Submit Status
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 and output
Sample Input
Sample Output
3 2
2 1 3
1 1
1
Hint
A0=−∞,A1=6,A2=2,A3=12,A4=−∞A0=−∞,A1=6,A2=2,A3=12,A4=−∞. So 11, 33 are both OK
Source
The 13th UESTC Programming Contest Final
题目大意:
求出任意一个峰值Ai,使得Ai>Ai+1&&Ai>Ai-1;
思路:
三分可以找一个波浪形状的函数的最大值(最小值)的某一个峰点的位子。
那么这个题就是一个煞笔三分了= =
第一次知道三分还有这种骚操作!
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;#define ll long long intint n,m;ll x[15000000];ll b[15000000];const ll mod=1e9+7;ll kuaisumi(ll a,ll b,ll p){ a%=p; ll ans=1; while(b) { if(b&1) { ans=ans*a; ans%=mod; } a=a*a; a%=mod; b/=2; } return ans;}ll Slove(int pos){ ll INF=-1000000000000000000; if(pos==0||pos==n+1)return INF; ll sum=0; for(int i=1;i<=m;i++) { sum=(sum+(b[i]*kuaisumi(x[pos],i,mod)))%mod; } return sum%mod;}int main(){ while(~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; int r=n; while(l<r-1) { int lm=(l+r)/2; int rm=(lm+r)/2; if(Slove(lm)<=Slove(rm)) { l=lm; } else r=rm; } for(int i=l;i<=r;i++) { if(Slove(i)>Slove(i+1)&&Slove(i)>Slove(i-1)) { printf("%d\n",i); break; } } }}
- UESTC 1048 Bob's vector【煞笔三分】
- Hrbust 2052 Alice and Bob【煞笔题啊】
- bob's Blog
- Bob's Problem
- Bob's Problem
- Bob's Problem
- hdu 4213 Bob’s Race
- HDU 4123 - Bob’s Race
- hdu 4123 Bob’s Race
- XTU 1185 Bob's Problem
- XTU-1185 Bob's Problem
- UESTC 1226 Huatuo's Medicine
- Kia's Calculation UESTC - 836
- 【UESTC 1516 Euclid's Game】
- 徐倩大煞笔
- 煞笔题
- HDU 3660 Alice and Bob's Trip
- hdoj 3660 Alice and Bob's Trip
- Git初识
- PAT 1021个位数统计
- xml解析之Dom4J
- ecilipse+tomcat+jrebel实现热部署
- Sql 从一张表查询数据插入到另外一张表中
- UESTC 1048 Bob's vector【煞笔三分】
- mac电脑mamp安装管理Apache和mysql
- 【C++】构造拷贝构造的N中调用情况的问题
- JSP JSTL函数<fn>
- java响应超时处理jdk自带方式处理
- 【Python】读取一个目录,将文件名称转换成 json 格式
- python中read() readline()以及readlines()用法
- Android 关于按两次返回 退出功能
- 导入代码到github库