NOIP 2017 跳房子

http://m.blog.csdn.net/c20190102/article/details/78550025


http://m.blog.csdn.net/huangzihaoal/article/details/78630659


通过了8组数据。  。。。还有两组啊!!


/*

7 4 10
2 6
5 -3
10 3
11 -3
13 1
17 6
20 2
输出 2、、、、

10 59 112 41 27 89 -50 112 -4 144 -45 187 42 196 35 237 8 262 2 269 -8 273 -37

输出 87 */ #include <bits/stdc++.h> //#define debug #define LL long long int using namespace std; int n,d,k; const int MM=500001; int dis[MM]; int score[MM]; int dp[MM]; deque<int> dq; bool check(int g){ memset( dp ,0 ,sizeof(dp) ); dis[0]=0; score[0]=0; dq.clear(); //dq.push_back(0); int jump1 = (g<d)? (d-g) : 1; int jump2 = g+d; // cout << "jump1 " << jump1 <<" "; //cout << "jump2 " << jump2 ; for(int i=1;i<=n;i++){ //这一行,由于删除掉的可能在下一次还可能有用。 调试了很久!!!还没有好办法 // for( int j=( dq.empty()? 0:dq.back()) ; j<=i-1; j++ ) dq.push_back( j ); dq.push_back( i-1 ); while( !dq.empty() && dis[i] - dis[ dq.front() ] > jump2 ) dq.pop_front(); //太远不行 //while ( !dq.empty() && dis[i] - dis[ dq.back() ] < jump1 ) dq.pop_back(); //太近也不行 deque<int>::iterator it; #ifdef debug cout << "debug "; for( it=dq.begin();it!=dq.end();it++){ cout << *it << " "; } cout << "end debug" << endl; #endif // debug if( dq.empty() ) { dp[i] = 0; return false; } else { dp[i] += score[ i ]; int temp=-100000; for( it = dq.begin();it!=dq.end();it++) if( dis[i] - dis[ *it ] >= jump1 )
                   //这一行,由于删除掉的可能在下一次还可能有用。所以在队伍后面没有删除。 调试了很久!!!只能用这个丑丑的代码了。
temp = max(temp, dp[ *it ] ); else break; dp[i] = dp[i] + temp ; #ifdef debug cout << "dp "; cout << i << " " << dp[i] << " "; cout << endl; #endif // debug if(dp[i] >= k) return true; } } return false;}int main(){cin>>n>>d>>k;for(int i=1; i<=n; i++){ cin >> dis[i]; cin >> score[i]; // 数据保证 dis递增}int left = 1;int right = 1000000; int ans=-1;while( left+1 < right ) { int middle = (left+right) / 2; if( check( middle ) ) { ans=middle; right = middle; } else left = middle;} cout << ans;return 0;}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值