ural 1998 The old Padawan
先预处理每一个点往前退几步
就一个trick。。要处理这一秒已经超出了要拿完所花的时间
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
typedef __int64 ll;
using namespace std; int c[100005],w[100005],s[100005],t[100005],tmp,N,n,m,k,i,cnt,pos,ans; int main()
{
while(~scanf("%d%d%d",&n,&m,&k))
{
for(i=1;i<=n;i++)
scanf("%d",&w[i]);
for(i=1;i<=m;i++)
scanf("%d",&t[i]);
s[n]=w[n];
tmp=n-1;
cnt=1;
while(s[n]<=k&&tmp>0)
{
s[n]+=w[tmp];
tmp--;
cnt++;
}
c[n]=cnt;
N=n-1;
while(N)
{
s[N]=s[N+1]-w[N+1];
cnt--;
while(s[N]<=k&&tmp>0)
{
s[N]+=w[tmp];
tmp--;
cnt++;
}
c[N]=cnt;
// printf("N:%d cnt:%d tmp:%d\n",N,cnt,tmp);
if(tmp<=0)
{
for(i=N;i>0;i--)
{
c[i]=i;
}
break;
}
N--;
}
//处理每一个分散注意力的秒
sort(t+1,t+m+1);
t[0]=0;
ans=0;
pos=0;
for(i=1;i<=m;i++)
{
tmp=(t[i]-t[i-1]);
pos+=tmp;
if(pos>n){//时间超出了全部拿完的时间
pos-=tmp;
break;
}
ans+=tmp;
pos=pos-1-c[pos-1]; }
ans+=(n-pos);
printf("%d\n",ans);
}
return 0;
}
ural 1998 The old Padawan的更多相关文章
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
- ural 2065. Different Sums
2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...
随机推荐
- hihocoder 1233 Boxes
题意:类汉诺塔的一个东西……移动规则与汉诺塔一样,但初始状态为题目中给出的每根棍上一个盘子,目标状态为盘子在棍上按大小顺序排列,盘子只能在相邻的棍儿上移动. 解法:广搜并打表记录从目标状态到所有可能的 ...
- spoj 694(后缀数组)
题意:求一个字符串的不重复子串的个数. 分析:对于下标为i的位置,能够产生的前缀子串个数为len-i(下标从0开始),对于与它字典序相邻的后缀产生的子串是重复的(就是他们的最长公共前缀),所以我们要减 ...
- nodejs+express +jade模板引擎 新建项目
先 安装 nodejsiDEAAM 2015/7/16 22:47:25然后安装 npm install expressiDEAAM 2015/7/16 22:47:35然后安装 npm instal ...
- CoffeeScript学习(3)—— 函数
CoffeeScript函数 如果大家有看我之前关于ES6的箭头函数的话,这一篇也不会很难理解.我们这一次可以说一下,关于两者的一些细微差别. 基本 在CoffeeScript中,任何函数都是用箭头函 ...
- Mysql数据库插入的中文字段值显示问号的问题解决
最近我使用myeclipse连接mysql数据库查询表中的数据,表中字段值为中文的字段显示问号,查了很多资料将解决方法总结如下: 步骤一:修改mysql数据库的配置文件my.ini或者my-defau ...
- Spring dependency checking with @Required Annotation
Spring's dependency checking in bean configuration file is used to make sure all properties of a cer ...
- [iOS微博项目 - 1.0] - 搭建基本框架
A.搭建基本环境 github: https://github.com/hellovoidworld/HVWWeibo 项目结构: 1.使用代码构建UI,不使用storyboard ...
- IPhone 设备状态、闪光灯状态
//判断闪光灯状态,修改默认的"CameraFlashOff" 按钮图片.转由 TGCameraFlash.m 控制图标切换 AVCaptureDevice *device ...
- Algorithms Part 1-Question 6- 2SUM Median-数和以及中位数问题
本次有两个编程问题,一个是求两个数的和满足一定值的数目,另一个是求中位数. 2SUM问题 问题描述 The goal of this problem is to implement a variant ...
- Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)
题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...