SGU 531 Bonnie and Clyde(二分)
2016-02-01 23:34
127 查看
[code]题意很见到就不说,只要预处理一下就行,不知道为什么有的用线段树写wa的那么惨。。。。。。
代码:
[code]// // Created by CQU_CST_WuErli // Copyright (c) 2015 CQU_CST_WuErli. All rights reserved. // // #include<bits/stdc++.h> #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <string> #include <vector> #include <list> #include <map> #include <queue> #include <stack> #include <set> #include <algorithm> #include <sstream> #define CLR(x) memset(x,0,sizeof(x)) #define OFF(x) memset(x,-1,sizeof(x)) #define MEM(x,a) memset((x),(a),sizeof(x)) #define For_UVa if (kase!=1) cout << endl #define BUG cout << "I am here" << endl #define lookln(x) cout << #x << "=" << x << endl #define SI(a) scanf("%d",&a) #define SII(a,b) scanf("%d%d",&a,&b) #define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c) #define rep(flag,start,end) for(int flag=start;flag<=end;flag++) #define Rep(flag,start,end) for(int flag=start;flag>=end;flag--) #define Lson l,mid,rt<<1 #define Rson mid+1,r,rt<<1|1 #define Root 1,n,1 #define BigInteger bign template <typename T> T gcd(const T& a,const T& b) {return b==0?a:gcd(b,a%b);} const int MAX_L=2005;// For BigInteger const int INF_INT=0x3f3f3f3f; const long long INF_LL=0x7fffffff; const int MOD=1e9+7; const double eps=1e-9; const double pi=acos(-1); typedef long long ll; using namespace std; const int N=200010; int x ,w ; int n,d; int LMax ,LMax_id ; int RMax ,RMax_id ; int main(){ #ifdef LOCAL freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin); // freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout); #endif while (SII(n,d)==2) { x[0]=-1; rep(i,1,n) { SII(x[i],w[i]); } LMax[1]=w[1];LMax_id[1]=1; rep(i,2,n) { if (w[i]>LMax[i-1]) { LMax[i]=w[i]; LMax_id[i]=i; } else { LMax[i]=LMax[i-1]; LMax_id[i]=LMax_id[i-1]; } } RMax =w ;RMax_id =n; Rep(i,n-1,1) { if (w[i]>RMax[i+1]) { RMax[i]=w[i]; RMax_id[i]=i; } else { RMax[i]=RMax[i+1]; RMax_id[i]=RMax_id[i+1]; } } // 1 3 4 6 10 11 // 1 2 3 4 5 6 // int pos=upper_bound(x+1,x+1+n,5)-x; // lookln(pos); int ans=-1; int li,ri; rep(i,1,n) { if (x[i]-d>=1) { int pos=upper_bound(x+1,x+1+n,x[i]-d)-x; pos-=1; if (pos>=1) { if (ans<w[i]+LMax[pos]) { ans=w[i]+LMax[pos]; li=i;ri=LMax_id[pos]; } } } if (x[i]+d<=x ) { int pos=lower_bound(x+1,x+1+n,x[i]+d)-x; if (pos<=n) { if (ans<w[i]+RMax[pos]) { ans=w[i]+RMax[pos]; li=i;ri=RMax_id[pos]; } } } } if (ans==-1) cout << -1 << ' ' << -1 << endl; else cout << li << ' ' << ri << endl; } return 0; }
相关文章推荐
- 坚果手机使用感受
- 坚果手机使用感受
- 9. Oracle深度学习笔记——性能调优汇总
- JAVA中接口与抽象类的区别
- HDU 4429 Split the Rectangle(暴力)
- C遇到的问题
- memcached系列之
- spark on yarn作业执行流程
- OSMC简介
- 好用的软件
- go中的main函数和init函数
- java常用数据类型
- go lang中的import
- Linux configure 参数解释
- 015 关于matlab更改默认路径的方法
- codeforce341 D题 Rat Kwesh and Cheese(复数)
- DatePicker使用
- AR--未来技术提前探索<3>[在汉明码上叠加一个3D模型]
- 记录有关802.11 mixed模式,关于AP发送下行数据部分
- CF621D 给出几种指数式子,分别将xyz代入。问哪个式子的值最大