http://acm.hnu.cn/online/?action=problem&type=show&id=12812&courseid=267
Broken Audio Signal |
Time Limit: 20000ms, Special Time Limit:50000ms, Memory Limit:65536KB |
Total submit users: 61, Accepted users: 38 |
Problem 12812 : No special judgement |
Problem 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.
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 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 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 |
Sample Input |
5 1 x 2 4 x 2 x x 2 1 2 2 2 1 2 1000000000 x 4 x 2 1 x 0 |
Sample Output |
3 none ambiguous none ambiguous none |
题意:x为一个数,第奇数个数要比两边的小,偶数要比两边的大,问x是多少,是否有解或是否有多个解。
AC代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int num1[1010],num2[1010];
char c;
bool flag;
int n,mi,mx;
void solve()
{ int i,j,k;
for(i=2;i<=n;i++)
if(num2[i-1]==1 && num2[i]==1)
{ printf("none\n");
return;
}
for(i=1;i<=n;i++)
if(num2[i]==0)
{ if(i&1)
{ if(i>1 && num2[i-1]==0)
{ if(num1[i-1]<=num1[i])
{ printf("none\n");
return;
}
}
if(i>1 && num2[i-1]==1)
{ mi=max(mi,num1[i]+1);
}
if(i<n && num2[i+1]==0)
{ if(num1[i+1]<=num1[i])
{ printf("none\n");
return;
}
}
if(i<n && num2[i+1]==1)
{ mi=max(mi,num1[i]+1);
}
}
else
{ if(i>1 && num2[i-1]==0)
{ if(num1[i-1]>=num1[i])
{ printf("none\n");
return;
}
}
if(i>1 && num2[i-1]==1)
{ mx=min(mx,num1[i]-1);
}
if(i<n && num2[i+1]==0)
{ if(num1[i+1]>=num1[i])
{ printf("none\n");
return;
}
}
if(i<n && num2[i+1]==1)
{ mx=min(mx,num1[i]-1);
}
}
}
if(mi==mx)
printf("%d\n",mi);
else if(mi<mx)
printf("ambiguous\n");
else
printf("none\n");
}
int main()
{ int i,j,k;
while(~scanf("%d",&n))
{ cin.ignore();
if(n==0)
break;
mi=0-1000000010;
mx=1000000010;
flag=true;
memset(num2,0,sizeof(num2));
for(i=1;i<=n;i++)
{ c=cin.peek();
while(c==' ')
{ cin.ignore();
c=cin.peek();
}
if(c=='x')
{ cin.ignore();
num2[i]=1;
}
else
scanf("%d",&num1[i]);
}
solve();
}
}