题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1998

  题意:有n个石头,每个石头有个重量,每个时间点你能让一个石头飞起来,但有m个时间点,你会分心,使得已经飞起来的石头会有重量之和大于k的石头掉下来,问你最终使的所有石头飞起来的时间。

  维护一个前缀和,然后二分就可以了。

 //STATUS:C++_AC_93MS_1113KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int t[N],sum[N];
int n,m,k; int binary(int l,int r,LL tar)
{
int mid;
while(l<r){
mid=(l+r)>>;
if(sum[mid]<tar)l=mid+;
else r=mid;
}
return l;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,a,w,ans;
while(~scanf("%d%d%d",&n,&m,&k))
{
for(i=;i<=n;i++){
scanf("%d",&a);
sum[i]=sum[i-]+a;
}
for(i=;i<=m;i++)
scanf("%d",&t[i]);
w=ans=;
for(i=;i<=m;i++){
w+=t[i]-t[i-]-;
if(w>=n){
ans+=n-(w-(t[i]-t[i-]-));
break;
}
ans=t[i];
w=binary(,w+,sum[w]-k)-;
}
if(w<n){
ans+=n-w;
} printf("%d\n",ans);
}
return ;
}

URAL-1998 The old Padawan 二分的更多相关文章

  1. ural 1998 The old Padawan

    先预处理每一个点往前退几步 就一个trick..要处理这一秒已经超出了要拿完所花的时间 #include <iostream> #include <cstring> #incl ...

  2. URAL 1196. History Exam (二分)

    1196. History Exam Time limit: 1.5 second Memory limit: 64 MB Professor of history decided to simpli ...

  3. URAL 1066 Garland 二分

    二分H2的位置,判断条件为是否有Hi < 0 #include <cstdio> #include <cstring> #include <cstdlib> ...

  4. URAL - 1486 Equal Squares 二维哈希+二分

    During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued about who o ...

  5. URAL 1948 H - The Robot on the Line 二分 + 数学

    http://acm.hust.edu.cn/vjudge/contest/126149#problem/H 给定一条二次函数 f (x) = a * x * x + b * x + c 求一个最小的 ...

  6. 【URAL 1486】Equal Squares(二维哈希+二分)

    Description During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued ...

  7. URAL 1822. Hugo II&#39;s War 树的结构+二分

    1822. Hugo II's War Time limit: 0.5 second Memory limit: 64 MB The glorious King Hugo II has declare ...

  8. ural 1153. Supercomputer

    1153. Supercomputer Time limit: 2.0 secondMemory limit: 64 MB To check the speed of JCN Corporation ...

  9. [二分匹配]URAL1721Two Sides of the Same Coin

    题意:给n个人,每个人都有3个参数,分别是名字,能做的事(a:statements  b:testdate  a.b都可以:anything),Rank 要求:一个人只能做一个事件,要两个人Rank相 ...

随机推荐

  1. python 捕获 shell/bash 脚本的输出结果

    #!/usr/bin/python## get subprocess module import subprocess ## call date command ##p = subprocess.Po ...

  2. 谈谈 char *num="123";和char num[4]="123";的区别

    最近写程序的时候发现这样一个问题 #include<iostream> #include <string.h> using namespace std; void revers ...

  3. C# 为WebBrowser设置代理,打开网页

    WebBrowser控件是基于IE浏览器的,所以它的内核功能是依赖于IE的,相信做.NET的人都知道. 今天的主题,和上一篇文章应该是差不多的,都是通过代理来实现功能的. 请看下面的代码: //1.定 ...

  4. Git基础(二)

    本章内容将介绍第二部分:本地仓储操作.为了加深对每个命令操作的理解,我们可以事先获取一个仓储边学边操作.这里首先 你要明白一个概念,所有本地工作目录下的文件状态无不在乎两种,已跟踪和未跟踪.已跟踪文件 ...

  5. JAVA反射技术的使用

    前言 在开发html使用jquery提交post的时候,可以使用jquery遍历from元素里面的input元素实现参数组合,这样就不用手动打参数了,特别是在参数很多的时候,费神费时. 我开发Andr ...

  6. UI开发中的Unit test新工具:网页抓屏比较

    在UI开发中,判断是否正常往往需要看到UI长的模样,所以一般的Unit test无法胜任. 现在有一款通过抓屏而后相素比较的方法,或许对于UI自动化测试能够起到比较好的改进效果. 具体请参见:http ...

  7. Jqgrid入门-Jqgrid分组的实现(八)

    上一章主要说明了如果实现Jqgrid列数据拖动,这一章主要讨论在Jqgrid中如何实现分组功能.         类似于Sql语句的Group By,Jqgrid提供了属性实现数据分组,这样表现数据会 ...

  8. UVa 1225 Digit Counting

    题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...

  9. iOS 9的新内容

    https://www.hackingwithswift.com/ios9 Search extensibility Update: I wrote a tutorial on Core Spotli ...

  10. 【解题报告】[动态规划] CodingTrip - 携程编程大赛 (预赛第一场)- 聪明的猴子

    原题: 聪明的猴子 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Problem D ...