首页 > 代码库 > HNU 12812 Broken Audio Signal

HNU 12812 Broken Audio Signal

题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12812

一直弄错了一个题意,教训啊,比赛最怕的就是弄错题意了

 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<cstdlib> 7 using namespace std; 8 const int maxn = 1000+5; 9 int num[maxn],X[maxn],flag[maxn];10 11 int main()12 {13 //    freopen("A2.out","w",stdout);14 //    freopen("A.in","r",stdin);15     int n;16     char str[30];17     while(scanf("%d",&n),n)18     {19         memset(flag,0,sizeof(flag));20         int num_x = 0,end = 0;21         for(int i = 1;i <= n;++i)22         {23             scanf("%s",str);24             if(str[0] == X || str[0] == x)25             {26                 flag[i] = 1;27                 X[num_x++] = i;28             }29             else num[i] = atoi(str);30             if(i > 1 && flag[i] == 1 && flag[i-1] == 1)31             end = 1;32         }33         if(num_x >= n || end)   /////全是x无法判断,超过两个x在一起也是无解34         {35             printf("none\n");36             continue;37         }38         for(int i = 1;i < n;++i)39         if(flag[i] == 0 && flag[i+1] == 0)40         {41             if(((i & 1) && num[i] >= num[i+1]) || (!(i & 1) && num[i] <= num[i+1]))42             {43                 end = 1;44                 break;45             }46         }47         if(end)        /////出现不符合规则的情况48         {49             printf("none\n");50             continue;51         }52         int l = -0x7fffffff,r = 0x7fffffff;53         for(int i = 0;i < num_x;++i)54         if(X[i] & 1)55         {56             if(X[i] > 1 && flag[X[i]-1] == 0)57             r = min(r,num[X[i]-1] - 1);58             if(X[i] < n && flag[X[i]-1] == 0)59             r = min(r,num[X[i]+1] - 1);60         }61         else62         {63             if(X[i] > 1 && flag[X[i]-1] == 0)64             l = max(l,num[X[i]-1] + 1);65             if(X[i] < n && flag[X[i]+1] == 0)66             l = max(l,num[X[i]+1] + 1);67         }68         if(l == r)69         printf("%d\n",l);70         else if(l > r)71         printf("none\n");72         else printf("ambiguous\n");73     }74     return 0;75 }
View Code