码迷,mamicode.com
首页 > 其他好文 > 详细

HNU 12812 Broken Audio Signal

时间:2014-07-22 00:10:34      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   

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

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

bubuko.com,布布扣
 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         else
62         {
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

HNU 12812 Broken Audio Signal,布布扣,bubuko.com

HNU 12812 Broken Audio Signal

标签:style   blog   http   color   os   io   

原文地址:http://www.cnblogs.com/xiaxiaosheng/p/3858637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!