HDU
来源:互联网 发布:青岛seo搜索排名优化 编辑:程序博客网 时间:2024/06/07 07:28
Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one day Klay comes up with a problem and ask him about it.
Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}: an+1…a2nan+1…a2n. Just like always, there are some restrictions on an+1…a2nan+1…a2n: for each number aiai, you must choose a number bkbk from {bi}, and it must satisfy aiai≤max{ajaj-j│bkbk≤j
题意
给出长度为n的两个数组a,b
其中1<=bi<=n
每次从b中取一个数(不重复取同一个数)
然后在 a数组中 将第j个数 设置为 a[bi]-bi~a[n+j-1]-(n+j-1) 中的最大值。
求,最大的sigm(a[n+1]~a[n+n]).
思路
应该有更简单的思路
我当时想的是
1.贪心:先把将b排序,然后从小到大取b中的数
因为肯定要越大的数尽量放在前面才可以保证 再后面安排的数会可能取到更大
2.然后就是一个优先队列,将(a[i]-i,i) push进去,大的a[i]-i 在前面。每次取b[i]的时候,判断一下下标,如果b[i]小于等于队首值的下标那么说明可以取到队首这个最大值;否则说明当前这个队首值取不到了,就需要将队首值弹出去,直到找到一个队首值的下标大于b[i] 说明可以取。每次取完需要把新的(a[i+n]-(i+n),i+n)push进去 ,因为可能后加进去的值会成为最大值。
注意
ans要开longlong 这个是肯定的
bug:最开始push(Pair(a[i]-i,i))push错了
写成了(a[i]-i,b[i])…….手残
嗯。。答案还要取余 不要忘了
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <vector>#include <queue>using namespace std;const long long MOD=1e9+7;int a[250005],b[250005];struct Pair{ int id; long long v; Pair(long long V,int ID){ v=V; id=ID; } friend bool operator <(const Pair a,const Pair b){ if(a.v!=b.v) return a.v<b.v; else return a.id>b.id; }};priority_queue<Pair> que;int main() { freopen("1003.in","r",stdin);// freopen("1003.txt","w",stdout); int n; while(~scanf("%d",&n)){ for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]); sort(b+1,b+1+n); while(!que.empty()) que.pop(); long long ans=0; for(int i=1;i<=n;i++){ que.push(Pair((long long )a[i]-i,i)); } for(int i=1;i<=n;i++){ struct Pair f=que.top(); if(b[i]>f.id){ while(1){ que.pop(); f= que.top(); if(f.id>=b[i])break; } } ans= (ans+f.v) % MOD;// cout<<f.v<<"**"<<endl; que.push(Pair(f.v-(n+i),n+i)); } printf("%lld\n",ans); }}/*90 11 01 22 -12 12 33 24 13 0*/
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- LitJson 不支持 float 类型数据
- ext2fs/ext2_fs.h:没有那个文件或目录
- PCIe学习笔记(28)--- PL
- dyld: Library not loaded: @rpath/libswiftCore.dylib
- ScrollView的setOnclickListener解决办法
- HDU
- 提取最后一个星号后的数字
- React创建组件的三种方式及其区别
- listview自己制造bug分析如何解决
- 避免死锁的建议
- mybatis的foreach标签的用法
- Java 7 新特性 和 一丢丢Servlet 3.X
- sails框架配置相关
- ajaxFileUpload上传问题,上传多次出现问题