URAL-1998 The old Padawan 二分
题目链接: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 二分的更多相关文章
- ural 1998 The old Padawan
先预处理每一个点往前退几步 就一个trick..要处理这一秒已经超出了要拿完所花的时间 #include <iostream> #include <cstring> #incl ...
- URAL 1196. History Exam (二分)
1196. History Exam Time limit: 1.5 second Memory limit: 64 MB Professor of history decided to simpli ...
- URAL 1066 Garland 二分
二分H2的位置,判断条件为是否有Hi < 0 #include <cstdio> #include <cstring> #include <cstdlib> ...
- URAL - 1486 Equal Squares 二维哈希+二分
During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued about who o ...
- 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 求一个最小的 ...
- 【URAL 1486】Equal Squares(二维哈希+二分)
Description During a discussion of problems at the Petrozavodsk Training Camp, Vova and Sasha argued ...
- URAL 1822. Hugo II's War 树的结构+二分
1822. Hugo II's War Time limit: 0.5 second Memory limit: 64 MB The glorious King Hugo II has declare ...
- ural 1153. Supercomputer
1153. Supercomputer Time limit: 2.0 secondMemory limit: 64 MB To check the speed of JCN Corporation ...
- [二分匹配]URAL1721Two Sides of the Same Coin
题意:给n个人,每个人都有3个参数,分别是名字,能做的事(a:statements b:testdate a.b都可以:anything),Rank 要求:一个人只能做一个事件,要两个人Rank相 ...
随机推荐
- Perl文件读写
Perl File Handling: open, read, write and close files #==================== Opening files Solution 1 ...
- Redis的过滤器(SCAN)功能
在写另一篇文章( link )的时候,涉及到过滤器(filter)功能.以前没有接触过,整理如下. 主要参考这两篇: http://blog.csdn.net/u011510825/article/d ...
- 51nod1161 Partial Sums
开始想的是O(n2logk)的算法但是显然会tle.看了解题报告然后就打表找起规律来.嘛是组合数嘛.时间复杂度是O(nlogn+n2)的 #include<cstdio> #include ...
- A1377. 楼房重建
题目:http://www.tsinsen.com/A1377 题解:分块大法好.每块维护一个有序表,修改暴力修改,查询从前往后跳即可. 代码: #include<cstdio> #inc ...
- mysql mac启动
设置别名 alias mysql=/usr/local/mysql/bin/mysql alias mysqladmin=/usr/local/mysql/bin/mysqladmin 修改密码 su ...
- Struts2的crud
struts2的crud引出的问题: 1.当Action里面有其他类的实例引用属性时,当要用请求参数为该对象的属性赋值时,如何将其压入栈顶. 2.当有的操作(list)不需要创建该属性的实例对象时,或 ...
- for...else循环
如果for循环完整结束,无break打断循环,那么执行else里面的内容,否则不执行. while True: n = raw_input('>') for x in n: if x == 'f ...
- 2015-10-09 Fri 晴 加快进度看书
最近老感觉每天不够用,每天7点起来,吃饭完了8点开始看书,不知道是我看书太慢了还是时间过得真的很快,不知不觉中午就到了.而这个时候我才看2章的内容,下午能多看3章内容.一本书也就一天的时候,而我现在还 ...
- Java多线程-工具篇-BlockingQueue
前言: 在新增的Concurrent包中,BlockingQueue很好的解决了多线程中,如何高效安全“传输”数据的问题.通过这些高效并且线程安全的队列 类,为我们快速搭建高质量的多线程程序带来极大的 ...
- jquery再学习(1)
一:jquery对象和js的dom对象相互转化 html代码 <ul> <li class="sxf" name="dd">第一< ...