双指针移动
来源:互联网 发布:dota2最新比赛数据 编辑:程序博客网 时间:2024/05/22 04:56
Problem Description
One day, ZHJ came across a warrior novel named Kunlun in library. Soon, ZHJ fall into it.
He tells everybody how deeply he loves Kunlun no matter whom he meets.
He found it attractive so he decided to read the novel in the next N days. However, ZHJ had
his own schedule. So every day he had only few minutes to spend on the book. Besides, he was
accustomed to reading a novel continuously, that is, once he started to read the novel, he would
not stop until he had read the entire novel.
ZHJ wondered when he should begin to read the novel so that he could spend the least days
on the novel.
He tells everybody how deeply he loves Kunlun no matter whom he meets.
He found it attractive so he decided to read the novel in the next N days. However, ZHJ had
his own schedule. So every day he had only few minutes to spend on the book. Besides, he was
accustomed to reading a novel continuously, that is, once he started to read the novel, he would
not stop until he had read the entire novel.
ZHJ wondered when he should begin to read the novel so that he could spend the least days
on the novel.
Input
The input contains several cases.
The first line of each case contains two space-seperated integers N(2 <= N <= 10^5) and S(1 <= S <= 10^8) where N means ZHJ decides to finish the novel in the next N days, S means the novel would cost ZHJ S minutes.Then N lines follows.The ith line contains an integer ai(1 <= ai <= 100) which means ZHJ has ai minutes' free time in the ith day.It is guaranteed that the sum of the free time of the N days is enough for ZHJ to finish the novel.
The first line of each case contains two space-seperated integers N(2 <= N <= 10^5) and S(1 <= S <= 10^8) where N means ZHJ decides to finish the novel in the next N days, S means the novel would cost ZHJ S minutes.Then N lines follows.The ith line contains an integer ai(1 <= ai <= 100) which means ZHJ has ai minutes' free time in the ith day.It is guaranteed that the sum of the free time of the N days is enough for ZHJ to finish the novel.
Output
For each test case, you should output a single line with a integer indicating the day ZHJ should start to read the novel.If there are several answers, output the smallest one.
Sample Input
2 1009910020 1001234567891011121314151617181920
Sample Output
215
双指针跑一遍~~~以前没接触过额~~
#include <iostream>#include <cstring>#include <cstdio>#define INF 0x3f3f3f3f#define BUG printf("here!\n")using namespace std;int num[100005];int main(){ int n,s; while(scanf("%d%d",&n,&s)!=EOF) { int i; for(i=0;i<n;i++) scanf("%d",&num[i]); int j=0; i=0; int ans=0; int sum=num[0]; int ff=INF; while(1) { if(sum>=s) { if(ff>j-i+1) { ans=i; ff=j-i+1; } sum=sum-num[i]; i=i+1; } else { if(j+1==n) break; sum=sum+num[j+1]; j++; } } printf("%d\n",ans+1); } return 0;}
- 双指针移动
- fseek() 移动文件指针
- C#----移动DataGridView指针
- 移动文件指针细节
- 堆栈指针及其移动
- fscanf的指针移动
- 指针地址的移动
- 数组,指针的移动
- leetcode 76. Minimum Window Substring 双指针 + Map + 移动窗口
- 使用键盘移动鼠标指针
- 指针移动任意字节数
- js指针移动小程序
- leetcode 328 --Odd Even Linked List 链表 双指针 移动节点
- leetcode 19. Remove Nth Node From End of List 双指针 + 移动窗口
- 关于RecordSet对象指针移动方法
- 指针移动的精华与应用实例
- C++文件操作指针移动-----off_t
- fseek c语言指针移动函数
- poj 1018
- 推荐系统实践
- 学习Java虚拟机
- HDOJ1730[SG博弈]
- vs2010 未能将脚本调试器附加到计算机上的进程。已附加了一个调试器
- 双指针移动
- Tomcat学习笔记(一)
- 索骥馆-OFFICE系列之《北风网Excel高端应用培训:多条件约束报表自动统计系统分析与制作》共4章更新完
- iOS: NSNotificationCenter的方法addObserverForName:object:queue:usingBlock:
- ubuntu 没有显示器 vnc登陆 分辨率设置
- VS2010+Opencv-2.4.0的配置攻略 & Win7x64+VS2012+OpenCV2.4.3+CMake2.8.10+TBB41重编译OpenCV
- java正则表达式
- 工作零散记忆_002
- hdu 3992(AC自动机 + 高斯消元 + 求期望(好题))