hdu 4928 Series 2
来源:互联网 发布:汽车配件编码查询软件 编辑:程序博客网 时间:2024/06/05 02:05
Series 2
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 499 Accepted Submission(s): 110
Problem Description
Let A be an integral series {A1, A2, . . . , An}.
The zero-order series of A is A itself.
The first-order series of A is {B1, B2, . . . , Bn-1, where Bi = Ai+1 - Ai.
The ith-order series of A is the first-order series of its (i - 1)th-order series (2<=i<=n - 1).
We say A is monotonic iff A1<=A2<=. . . <=An or A1>= A2 >=. . . >= An.
A is kth-order monotonic iff all ith-order series (0<=i<=k) are monotonic, and (k + 1)th-order are not.
Specially, if the zero-order series of A is not monotonic, then A is named ugly series. If all ith-order (0<=i<=n - 1) series of A are monotonic, then A is a nice series.
Given A, determine whether it’s a ugly series or nice series. If both are not, determine k.
The zero-order series of A is A itself.
The first-order series of A is {B1, B2, . . . , Bn-1, where Bi = Ai+1 - Ai.
The ith-order series of A is the first-order series of its (i - 1)th-order series (2<=i<=n - 1).
We say A is monotonic iff A1<=A2<=. . . <=An or A1>= A2 >=. . . >= An.
A is kth-order monotonic iff all ith-order series (0<=i<=k) are monotonic, and (k + 1)th-order are not.
Specially, if the zero-order series of A is not monotonic, then A is named ugly series. If all ith-order (0<=i<=n - 1) series of A are monotonic, then A is a nice series.
Given A, determine whether it’s a ugly series or nice series. If both are not, determine k.
Input
The input consists of several test cases. The first line of input gives the number of test cases T (T<=50).
For each test case:
The first line contains a single integer n(1<=n<=105), which denotes the length of series A.
The second line consists of n integers, describing A1, A2, . . . , An. (0<=|Ai|<=260)
For each test case:
The first line contains a single integer n(1<=n<=105), which denotes the length of series A.
The second line consists of n integers, describing A1, A2, . . . , An. (0<=|Ai|<=260)
Output
For each test case, output either ugly series, nice series or a single integer k.
Sample Input
431 3 241 4 6 741 3 4 75-1 0 3 11 29
Sample Output
ugly series nice series 0nice series
Author
BUPT
Source
2014 Multi-University Training Contest 6
题解看这:http://weibo.com/p/1005051809706204/weibo?from=page_100505_home&wvr=5.1&mod=weibomore#3740344145782887
看完题解后发现这道题只要缩点,就不会超时。复杂度为NlogV
代码:
#include <iostream>#include <algorithm>#include <cstdio>#include <string>#include <cstring>#include <cmath>#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#include <bitset>#include <functional>#include <sstream>#include <iomanip>#include <cmath>#include <cstdlib>#include <ctime>#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;#define INF 1e9#define maxn 100005#define maxm 100005+10const ll mod = 1e10+7;#define eps 1e-7#define PI acos(-1.0)#define rep(i,n) for(int i=0;i<n;i++)#define rep1(i,n) for(int i=1;i<=n;i++)#define scan(n) scanf("%d",&n)#define scan2(n,m) scanf("%d%d",&n,&m)#define scans(s) scanf("%s",s);#define ini(a) memset(a,0,sizeof(a))#define out(n) printf("%d\n",n)using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1ll a[2][maxn]; int main(){#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);// freopen("out.txt","w",stdout);#endifint T;int n;cin>>T;while(T--){scanf("%d",&n);ini(a);rep1(i,n) scanf("%I64d",&a[0][i]);int s = 0,start = 1,end = n;bool finish = 1;rep(i,n){while(start < end && a[s][start] == 0) start++; //缩点start = max(1 ,start-1);while(end > start && a[s][end] == 0) end--;end = min(end + 1,n - i);if(start >= end) break;int inc = 1, dec = 1;for(int j = start;j < end; j++){if(a[s][j] > a[s][j+1]) inc = 0;else if(a[s][j] < a[s][j+1]) dec = 0;}finish = inc | dec;if(!finish){if(i == 0) puts("ugly series");else printf("%d\n",i - 1);break;}for(int j = start;j < end; j++){a[s^1][j] = a[s][j+1] - a[s][j];}s ^= 1;}if(finish)puts("nice series");}return 0;}
0 0
- HDU 4928 Series 2
- 【HDU 4928】Series 2
- hdu 4928 Series 2
- hdu 4928 Series 2
- 【HDU】4928 Series 2 模拟
- hdu 4928 Series 2 (优化+模拟)
- hdu 4928 Series 2 (优化+模拟) 多次导数相关(数范围限制突破)
- HDU 4927 Series 1
- HDU 4927 Series 1
- HDU 4927 Series 1
- hdu 4927 Series 1
- hdu 4927 Series 1
- hdu 4927Series 1
- hdu 4927 Series 1
- HDU 4927 Series 1
- 【HDU】4927 Series 1 高精度
- HDU 4927 Series 1(瞎搞)
- hdu 4927 Series 1 高精度
- RLC模块的简单介绍
- 安卓网络编程一(学习安卓4.0网络编程)-------下载图片(书中代码bug探讨)
- 在Ubuntu12.04上安装中文输入法
- 物料提升机的最大功率有规定吗
- jQuery.Autocomplete 支持中文
- hdu 4928 Series 2
- Android中的binder
- 设计模式六大原则(5):迪米特法则
- List与vector的区别
- 人见人爱A-B(2034)
- C#多线程面面观
- PHP中变量为什么要用$?
- STL中基本的算法(一)
- 剑指offer 2.4 旋转数组