zoukankan      html  css  js  c++  java
  • HDU 6205 尺取

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

    /** @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
    ", l);
    	}
        return 0;
    }
    
  • 相关阅读:
    软件工程个人作业01
    阅读计划及浅读问题
    引言作业1
    多态和异常分析课后
    大道至简七八章阅读
    接口与继承 课后实践
    构建执法阅读笔记02
    冲刺第五天
    学习进度条七
    冲刺第四天
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/7523854.html
Copyright © 2011-2022 走看看