容易看出来,扩增一倍,找最长的区间就行了

/** @Date    : 2017-09-11 12:43:11
* @FileName: 1012.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e6+20;
const double eps = 1e-8; int n;
int a[2*N];
int main()
{
while(~scanf("%d", &n))
{
int x, y;
for(int i = 0; i < n; i++)
scanf("%d", a + i);
for(int i = 0; i < n; i++)
scanf("%d", &y), a[i] = a[i + n] = a[i] - y;
LL t = 0;
int l = 0;
for(int i = 0; i < 2 * n; i++)
{ t += a[i];
//cout <<i << t << endl;
if(i - l + 1 == n) break;
if(t < 0)
{
l = i + 1;
t = 0;
}
}
printf("%d\n", l);
}
return 0;
}

HDU 6205 尺取的更多相关文章

  1. HDU 5289 尺取

    Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  2. HDU 6205(尺取法)2017 ACM/ICPC Asia Regional Shenyang Online

    题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Clar ...

  3. hdu 5672 尺取还是挺好用的

    先简单介绍下尺取法 http://blog.chinaunix.net/uid-24922718-id-4848418.html 尺取法就是在卡给定条件的时候 不断的改变下标 起点 终点 #inclu ...

  4. 【单调队列+尺取】HDU 3530 Subsequence

    acm.hdu.edu.cn/showproblem.php?pid=3530 [题意] 给定一个长度为n的序列,问这个序列满足最大值和最小值的差在[m,k]的范围内的最长子区间是多长? [思路] 对 ...

  5. 【尺取】HDU String

    http://acm.hdu.edu.cn/showproblem.php?pid=5672 [题意] 给定一个小写英语字母组成的字符串,求这个字符串一共包含多少个至少有m个不同字母的连续子序列 [思 ...

  6. 【尺取】HDU Problem Killer

    acm.hdu.edu.cn/showproblem.php?pid=5328 [题意] 给定一个长度为n的正整数序列,选出一个连续子序列,这个子序列是等差数列或者等比数列,问这样的连续子序列最长是多 ...

  7. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  8. hdu 6231 -- K-th Number(二分+尺取)

    题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...

  9. HDU 5178 pairs【二分】||【尺取】

    <题目链接> 题目大意: 给定一个整数序列,求出绝对值小于等于k的有序对个数. 解题分析: $O(nlong(n))$的二分很好写,这里就不解释了.本题尺取$O(n)$也能做,并且效率很不 ...

随机推荐

  1. listagg wm_concat 行转列

    一. 这个写法和wm_concat相似,listagg(day,',')要把哪一列转换为同一行within group (order by day)同一行如何排序 with temp as ( ' d ...

  2. Java 将数字转为16进制,然后转为字符串类型

    public class ArrayTest3 { public static void main(String[] args){ System.out.println(toHex(60)); } / ...

  3. 1104 文法产生这段C程序的推导过程

  4. Qt容器类汇总说明

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt容器类汇总说明     本文地址:http://techieliang.com/2017/ ...

  5. 设计模式php篇(一)————单例模式

    话不多说,直接上代码: <?php namespace DesignPattern; /** * php设计模式之单例模式 */ class SingleInstance { private s ...

  6. 【Apache】ab工具

    格式:ab  [options] [http://]hostname[:port]/path -n requests Number of requests to perform //在测试会话中所执行 ...

  7. java 基础 --final--008

    finally:被finally控制的语句一定会执行,但是如果执行之前jvm退出了,就不会执行了.比如System.exit(0);final:常见的可以修饰类(该类不能被继承) 方法(方法不能被重写 ...

  8. 【Python】Python处理csv文件

    Python处理csv文件 CSV(Comma-Separated Values)即逗号分隔值,可以用Excel打开查看.由于是纯文本,任何编辑器也都可打开.与Excel文件不同,CSV文件中: 值没 ...

  9. HDU 6035 Colorful Tree(dfs)

    题意:一棵有n个点的树,树上每个点都有颜色c[i],定义每条路径的值为这条路径上经过的不同颜色数量和.求所有路径的值的和. 可以把问题转化为对每种颜色有多少条不同的路径至少经过这种颜色的点,然后加和. ...

  10. Qt——数据的隐式共享

    一.隐式共享类 在Qt中有很多隐式共享类( Implicitly Shared Classes ),什么是隐式共享呢,请参考官方文档的说明. 好吧,翻译一下—— 许多C++类隐式地共享数据,使得资源使 ...