(校赛)URAL 1998 The old Padawan
来源:互联网 发布:十堰网络推广学校 编辑:程序博客网 时间:2024/06/11 05:59
Luke Skywalker is having exhausting practice at a God-forsaken planet Dagoba. One of his main difficulties is navigating cumbersome objects using the Power. Luke’s task is to hold several stones in the air simultaneously. It takes complete concentration and attentiveness but the fellow keeps getting distracted.
Luke chose a certain order of stones and he lifts them, one by one, strictly following the order. Each second Luke raises a stone in the air. However, if he gets distracted during this second, he cannot lift the stone. Moreover, he drops some stones he had picked before. The stones fall in the order that is reverse to the order they were raised. They fall until the total weight of the fallen stones exceeds k kilograms or there are no more stones to fall down.
The task is considered complete at the moment when Luke gets all of the stones in the air. Luke is good at divination and he can foresee all moments he will get distracted at. Now he wants to understand how much time he is going to need to complete the exercise and move on.
Input
The first line contains three integers: n is the total number of stones, m is the number of moments when Luke gets distracted and k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109). Next n lines contain the stones’ weights wi (in kilograms) in the order Luke is going to raise them (1 ≤ wi ≤ 104). Next m lines contain moments ti, when Luke gets distracted by some events (1 ≤ ti ≤ 109, ti < ti+1).
Output
Print a single integer — the number of seconds young Skywalker needs to complete the exercise.
Sample
5 1 4123454
8
今天看到了二分方法,好犀利。。#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>using namespace std;const int maxn=1e5;int T[maxn],a[maxn],sum[maxn];int n,t,k;int solve(int x)//二分得大于x的最小位置i{ int l=0,r=n; int ans; while(l<=r) { int mid=(l+r)>>1; if(sum[mid]<x) { ans=mid; l=mid+1; } else r=mid-1; } return ans;}int main(){ while(cin>>n>>t>>k) { sum[0]=0; for(int i=1;i<=n;i++) { cin>>a[i]; sum[i]=sum[i-1]+a[i]; } for(int i=1;i<=t;i++) cin>>T[i];//第几秒 t++; T[t]=2000000000;//最后没有分心时间的时候可以做if语句做完事情 int pos=0,to; int ans=0; for(int i=1;i<=t;i++) { if(n-pos<T[i]-ans)//T[i]时间内可以做完 { ans+=n-pos; break; } else { to=T[i]-ans+pos;//分心的时候到了第几个位置及当前位置pos加上还要走的距离(T[i]-ans); ans+=T[i]-ans;//ans,当前走了多少时间 pos=solve(sum[to-1]-k);//找到分心后的位置 } } cout<<ans<<endl; } return 0;}
1 0
- (校赛)URAL 1998 The old Padawan
- Ural 1998 The old Padawan(二分)
- ural 1998 The old Padawan
- URAL 1998 The old Padawan
- ural 1998 The old Padawan (模拟+二分)
- The old Padawan(二分)
- URAL1998-The old Padawan
- GYM 100285 I. The old Padawan(二分+简单模拟)
- Ural 1998 The old Padawa
- (校赛)URAL 1991 The battle near the swamp
- 1769. Old Ural Legend [ACM]
- The Old RegExp Matcher
- Goat in the Garden (ural 1348)
- Ural 2018The Debut Album(DP)
- URAL 2018 The Debut Album(dp)
- URAL 2018. The Debut Album (dp)
- URAL 2018 The Debut Album(DP)
- Ural 1017 The Staircases
- 机房收费系统详细配置
- 十多名地方官因访民喝农药自杀案被处分
- Linux下bugzilla的安装方法
- Read 系统调用在用户空间中的处理过程
- DSP流程图
- (校赛)URAL 1998 The old Padawan
- 矩阵快速幂
- hd 1013 Digital Roots
- 第三方类库
- GUI单元测试方法
- 禁止屏幕翻转或翻转时禁止OnCreate
- VS2010/MFC入门编程十七(多线程的创建,包括工作线程和用户界面线程)
- Protel各层定义大全
- Gson使用