题目只给了500ms,注意超时问题,一开始的几发都超时了,后来想到了预处理,从后往前推即可,为了防止t的大小可能有问题,所以进行了排序,还有人用二分做的,比较犀利先贴一个我的思路

#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>#define ll long long#define eps 1e-7#define inf 0xfffffff
const ll INF = 1ll<<61;using namespace std;//vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p;
//int n,m,k;int w[100000 + 5];
int t[100000 + 5];
int sum[100000 * 2];//当前往前面第一次超过k的石头和
int step[100000 * 2];//当前往前需要回头几步void clear() {memset(w,0,sizeof(w));memset(t,0,sizeof(t));memset(sum,0,sizeof(sum));memset(step,0,sizeof(step));
}void init() {sum[n] = w[n];int tempn = n - 1;int cnt = 1;while(sum[n] <= k && tempn >=1) {//最后一个要单独拎出来cnt++;sum[n] += w[tempn--];}step[n] = cnt;int tmpn = n - 1;while(tmpn) {sum[tmpn] = sum[tmpn + 1] - w[tmpn + 1];cnt--;while(sum[tmpn] <=k &&tempn >= 1) {cnt++;sum[tmpn] += w[tempn--];}step[tmpn] = cnt;if(tempn <= 0) {for(int i=tmpn;i>0;i--)//前面和已经无法超过k,所以退到直至第一次为止step[i] = i;break;}tmpn--;}
}int main() {while(scanf("%d %d %d",&n,&m,&k) == 3) {clear();for(int i=1;i<=n;i++)scanf("%d",&w[i]);for(int i=1;i<=m;i++)scanf("%d",&t[i]);sort(t + 1,t + m + 1);init();int ans = 0;int mark = 0;for(int i=1;i<=m;i++) {int cha = (t[i] - t[i-1]);mark += cha;if(mark > n) {mark -= cha;break;}ans += cha;mark = mark - 1 - step[mark - 1];}ans += n - mark;printf("%d\n",ans);}return EXIT_SUCCESS;
}/*5 2 41
2345455 2 43234534*/

接下来是二分做的,

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;
#define N 100010
int a[N],t[N],sum[N],n,m,k,ans;
int find(int x)
{int l=0,r=n,res=0;while(l<=r){int mid=(l+r)/2;if(sum[mid]<x){res=mid;l=mid+1;}else{r=mid-1;}}return res;
}
int main()
{while(scanf("%d%d%d",&n,&m,&k)!=EOF){for(int i=1;i<=n;i++){scanf("%d",&a[i]);sum[i]=sum[i-1]+a[i];}for(int i=1;i<=m;i++)scanf("%d",&t[i]);m++;t[m]=2000000000;ans=0;int pos=0,to;for(int i=1;i<=m;i++){if(n-pos<t[i]-ans){ans+=n-pos;break;}else{to=t[i]-ans+pos;ans+=t[i]-ans;pos=find(sum[to-1]-k); }}printf("%d\n",ans);}return 0;
}

URAL 1998 The old Padawan相关推荐

  1. Ural 1998 The old Padawan(二分)

    点击打开题目链接 1998. The old Padawan Time limit: 0.5 second Memory limit: 64 MB Yoda: Use the Force. Yes. ...

  2. URAL 1998 The old Padawan 二分

    The old Padawan 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1998 Description Yoda: Use th ...

  3. ural 1998 The old Padawan

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

  4. ural 1998 The old Padawan (模拟+二分)

    题意: 有一个人捡按一定顺序捡石头,每秒都能捡起一个,但是他有时会分心,这是不但不能举石头, 而且手中的石头还会掉,直到没有石头可以掉下来或者掉下来的石头的总重量>k.依次给出n个 石头的重量和 ...

  5. Ural 1018 (树形DP+背包+优化)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 题目大意:树枝上间连接着一坨坨苹果(不要在意'坨'),给 ...

  6. bzoj1814 Ural 1519 Formula 1(插头dp模板题)

    1814: Ural 1519 Formula 1 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 924  Solved: 351 [Submit][S ...

  7. URAL 1635 Mnemonics and Palindromes

    URAL 1635 思路:区间dp+贪心,先n^2处理出每段区间是否是回文串,然后贪心地找每一段1到i的最少分割. 代码: #include<bits/stdc++.h> using na ...

  8. AGI:走向通用人工智能的【哲学】之现实世界的虚拟与真实——带你回看1998年的经典影片《The Truman Show》感悟“什么是真实”

    AGI:走向通用人工智能的[哲学]之现实世界的虚拟与真实--带你回看1998年的经典影片<The Truman Show>感悟"什么是真实" 导读:今天写的这篇文章,完 ...

  9. [代码]ural 1655 Somali Pirates

    Abstract ural 1655 Somali Pirates dp Source http://acm.timus.ru/problem.aspx?space=1&num=1655 So ...

最新文章

  1. 第三次作业---读《构造之法》1-5章有感
  2. 天翼云从业认证(1.2)存储的概念、体系结构、块存储、对象存储、文件存储以及 RAID 磁盘管理技术
  3. 火影忍者手游服务器维护4月4,火影忍者手游4月14日联服公告-火影忍者手游4月14日联服时间_牛游戏网...
  4. 【ElasticSearch】Es 源码之 Discovery DiscoveryModule Coordinator 源码解读
  5. kpi绩效考核流程图_KPI绩效考核法
  6. c语言中用分数表示结果,C语言实例 计算分数的精确值
  7. 【元胞自动机】基于matlab元胞自动机收费站交通问题【含Matlab源码 357期】
  8. idea报错:不支持发行版本5的错误,快速解决方案
  9. Vue 导出excel 导出多个sheet
  10. 最好的3个txt阅读器
  11. 安卓 手机硬改 工具下载 一键新机 改串 抹机 root隐藏 改串号MEID imei SN信息 工具教程分享
  12. 8.15-30题目归档
  13. 渲染模式 - 标准模式(standards mode) 和 兼容模式(quriks mode)
  14. beeline软件_Beeline
  15. 小米手机扩容教程_小米4 16g升级64g教程:小米4 16g扩张64g步骤
  16. 智能硬件产品盈利模式
  17. APP自动化遇到问题总结-持续更新
  18. 外网业务访问故障,ping时通时断,显示有请求超时time out处理过程
  19. 家里WiFi慢?几招帮你解决
  20. 如何零基础开始学编程

热门文章

  1. linux下强制踢出普通用户
  2. 零基础自学python?大专生靠python涨薪8K,成功上岸,分享全套学习方法及经验
  3. oracle 自动填充,jQuery 实现自动填充邮箱功能(带下拉提示)
  4. 开卷有益 今天你读书了么?
  5. 14Cr1MoR容器、14Cr1MoR对应材质SA387Gr11CL2
  6. 历届真题 杨辉三角形【第十二届】【省赛】【B组】
  7. html中size是设置什么意思,CSS的font-size-adjust属性有什么用?
  8. linux下repo是什么文件夹,yum的repo文件详解、以及epel简介、yum源的更换
  9. 《Deep Learning Techniques for Music Generation – A Survey》深度学习用于音乐生成——书籍阅读笔记(一)Chapter 1
  10. 联想笔记本Manjaro dde 18 安装疑难杂症解决