湖大训练赛1 Broken Audio Signal

来源:互联网 发布:淘宝童装店招图片大全 编辑:程序博客网 时间:2024/09/21 09:05

Broken Audio SignalTime Limit: 20000ms, Special Time Limit:50000ms, Memory Limit:65536KBTotal submit users: 66, Accepted users: 40Problem 12812 : No special judgementProblem description

Nathan O. Davis is a student at the department of integrated systems.

Today's agenda in the class is audio signal processing. Nathan was given a lot of homework out. One of the homework was to write a program to process an audio signal. He copied the given audio signal to his USB memory and brought it back to his home.

When he started his homework, he unfortunately dropped the USB memory to the floor. He checked the contents of the USB memory and found that the audio signal data got broken.

There are several characteristics in the audio signal that he copied.

  • The audio signal is a sequence of N samples.

  • Each sample in the audio signal is numbered from 1 to N and represented as an integer value.

  • Each value of the odd-numbered sample(s) is strictly smaller than the value(s) of its neighboring sample(s).

  • Each value of the even-numbered sample(s) is strictly larger than the value(s) of its neighboring sample(s).

He got into a panic and asked you for a help. You tried to recover the audio signal from his USB memory but some samples of the audio signal are broken and could not be recovered. Fortunately, you found from the metadata that all the broken samples have the same integer value.

Your task is to write a program, which takes the broken audio signal extracted from his USB memory as its input, to detect whether the audio signal can be recovered uniquely.


Input

The input consists of multiple datasets. The form of each dataset is described below.

N
a1 a2
 ... aN

The first line of each dataset consists of an integer, N (2 ≤ N ≤ 1,000)N denotes the number of samples in the given audio signal. The second line of each dataset consists of N values separated by spaces. The i-th value, ai, is either a character x or an integer between -10^9 and 10^9, inclusive. It represents the i-th sample of the broken audio signal. If ai is a character x , it denotes that i-th sample in the audio signal is broken. Otherwise it denotes the value of the i-th sample.

The end of input is indicated by a single 0. This is not included in the datasets.

You may assume that the number of the datasets does not exceed 100.


Output

For each dataset, output the value of the broken samples in one line if the original audio signal can be recovered uniquely. If there are multiple possible values, output ambiguous. If there are no possible values, output none.


Sample Input
51 x 2 4 x2x x21 222 121000000000 x4x 2 1 x0
Sample Output
3noneambiguousnoneambiguousnone
Problem SourceJAG Practice Contest for ACM-ICPC Asia Regional 2013

题意:给一个长度为n的序列,其中有且只有一个满足条件要求输出唯一的这个数,有多个满足条件的输出ambiguous,不可能满足条件的输出none。条件是:奇数位上的数一定小于相邻偶数位上的数,同理,偶数位上的数一定大于相邻奇数位上的数。但是这个序列缺失了一个数,用x表示。

题解:我们可以把x如果是偶数位就把旁边奇数位的取最大值(min),x是奇数位就把旁边偶数位取最小值(max),最后把max-min。如果结果等于2就代表有唯一的值(min+1 or max-1)如果结果大于2就表示有多个值,如果小于的话肯定就是不成立的。当然还有默认情况。还有相邻两个x的情况这样肯定是none的。

#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <queue>#include <map>#include <stack>#include <list>#include <vector>using namespace std;#define ll __int64char a[1100][1100];int b[1100];int n,i,j;int main(){while (~scanf("%d",&n) && n){int t=0;getchar();int f=0,o=0;for (i=1;i<=n;i++){scanf("%s",&a[i]);if (o>=2) f=1;if (strstr(a[i],"x")) o++;else o=0;if (strstr(a[i],"x")==NULL && i!=1 && strstr(a[i-1],"x")==NULL){int k1=atoi(a[i]);int k2=atoi(a[i-1]); //k1是后一个 if (i % 2==0) {if (k1<=k2) f=1;}else if (k1>=k2) f=1;}if (strstr(a[i],"x"))b[t++]=i;}if (f==1 || t==n){printf("none\n");continue;}else if (t==0) {printf("ambiguous\n");continue;}ll min=-1e9-100,max=1e9+100;for (i=0;i<t;i++){if (b[i] % 2==0) //偶数,大于周边min{if (strstr(a[b[i]-1],"x")==NULL && b[i]-1!=0){int k=atoi(a[b[i]-1]);if (min<k) min=k;}if (strstr(a[b[i]+1],"x")==NULL && b[i]+1<=n){int k=atoi(a[b[i]+1]);if (min<k) min=k;}}else{if (strstr(a[b[i]-1],"x")==NULL && b[i]-1!=0){int k=atoi(a[b[i]-1]);if (max>k) max=k;}if (strstr(a[b[i]+1],"x")==NULL && b[i]+1<=n){int k=atoi(a[b[i]+1]);if (max>k) max=k;}}}if (max-min==2) printf("%I64d\n",min+1);else if (max-2>min) printf("ambiguous\n");else printf("none\n");}return 0;}



0 0
原创粉丝点击