Non-negative Partial Sums
来源:互联网 发布:js关闭微信内置浏览器 编辑:程序博客网 时间:2024/06/02 02:40
这个题我自己还没搞定,看了好久,最后没核心部分还真是清楚,知道的麻烦留言一下下,或者加我 qq:997930294给我解释一下,万分感谢
描述
You are given a sequence of n numbers a0,....,an-1. A cyclic shift by k positions (0≤k≤n-1) results in the following sequence : ak,ak+1,...,an-1,a0,a1,...,ak-1. How many of the n cyclic shifts satisfy the condition that the sum of the first i numbers is greater than or equal to zero for all i with 1≤i≤n?
输入
Each test case consists of two lines. The first contains the number n(1≤n≤106),the number if integers in the sequence. The second contains n integers a0,...,an-1(-1000≤ai≤1000) representing the sequence of numbers. The input will finish with a line containing 0.
输出
Each test case consists of two lines. The first contains the number n(1≤n≤106),the number if integers in the sequence. The second contains n integers a0,...,an-1(-1000≤ai≤1000) representing the sequence of numbers. The input will finish with a line containing 0.
样例输入
2 2 1
3
-1 1 1
1
-1
0
样例输出
2
0
#include <stdio.h>#include<iostream>#include <string.h>using namespace std;#define MAX 2100000struct node { int sum,id; }qu[MAX]; int n,head,tail,ans; int sum[MAX],arr[MAX]; int main() { int i,j,k; while (scanf("%d",&n) != EOF) { if (n == 0) break; ans = head = tail = 0; for (i = 1; i <= n; ++i) { scanf("%d",&arr[i]); sum[i] = sum[i-1] + arr[i]; } // for(i=1;i<=n;i++)cout<<sum[i]<<" "; for (i = 1; i <= n; ++i) sum[i+n] = sum[i+n-1] + arr[i]; // for(i=1;i<=2*n;i++)cout<<sum[i]<<" "; for (i = 1; i <= 2 * n; ++i)//这个for循环里的各种语句不懂,知道的请留言解释一下 { while (tail < head && sum[i] < qu[head-1].sum) head--; qu[head].sum = sum[i]; qu[head].id = i; head++; if (i > n && qu[tail].sum >= sum[i-n]) ans++; while (tail < head && qu[tail].id <= i - n + 1) tail++; } printf("%d\n",ans); } return 0; }
- Non-negative Partial Sums
- Non-negative Partial Sums HDU
- hdu Non-negative Partial Sums(单调队列)
- UVA 12393 Non-negative Partial Sums
- hdu 4193 Non-negative Partial Sums
- Hdu4193 Non-negative Partial Sums (单调队列)
- Non-negative Partial Sums 单调队列
- HDU 4193 Non-negative Partial Sums
- HDU-4193 Non-negative Partial Sums
- 【HDU4193】Non-negative Partial Sums-单调队列
- HDU 4193 Non-negative Partial Sums(单调队列)
- POJ-4040(单调队列)(Non-negative Partial Sums )
- HDU OJ 4193 Non-negative Partial Sums 【单调队列】
- HDU-4193 Non-negative Partial Sums 单调队列
- hdu 4193 - Non-negative Partial Sums(滚动数列)
- 单调队列-hdu-4193-Non-negative Partial Sums
- 单调队列—— HDU 4193 Non-negative Partial Sums
- 【单调队列】hdu 4193 Non-negative Partial Sums
- 手势拖动布局,出现新区域
- Android开发:什么是IBinder
- android中布局说明
- HDU 4430Yukari's Birthday2012现场赛K题(幂打表 思维 枚举+二分)
- NY--95 -- 众数问题 [水]
- Non-negative Partial Sums
- 用系统时间+序列+触发器 实现自动加入id并且实现唯一
- 主板维修技巧
- log4j配置祥解
- windows下载android 完整源码
- Python 学习笔记: id(), ==, is 之间的区别
- 《无源无线通信》
- POJ 1228 Grandpa's Estate【稳定凸包判断】
- 数据库左连接、右连接、全连接、交叉连接、自然连接