Broken Audio Signal - HUN 水题

本文探讨了在音频信号处理中遇到的难题,特别是当音频信号数据受损时如何进行恢复。通过提供一种算法来处理受破坏的音频信号,并确定是否能唯一地恢复原始音频信号,该文展示了如何在数据丢失的情况下保持音频信号的完整性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

  • 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
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();
  }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值