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

蓝桥杯 蚂蚁感冒

时间:2017-04-03 11:41:00      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:iostream   logs   ++   clu   else   abs   蚂蚁感冒   bsp   std   

思路:

脑洞题。

蚂蚁碰面的时候不是掉头回去,而是互相“穿过”。

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 using namespace std;
 5 
 6 int n, a[55];
 7 int main()
 8 {
 9     cin >> n;
10     cin >> a[0];
11     bool dir = true;
12     if (a[0] < 0)
13         dir = false;
14     bool flag = false;
15     for (int i = 1; i < n; i++)
16     {
17         cin >> a[i];
18         if (dir && a[i] < 0 && abs(a[i]) > a[0] ||
19             !dir && a[i] > 0 && a[i] < abs(a[0]))
20             flag = true;
21     }
22     if (!flag)
23         puts("1");
24     else
25     {
26         int cnt = 1;
27         for (int i = 1; i < n; i++)
28         {
29             if (dir)
30             {
31                 cnt += (a[i] < 0 && abs(a[i]) > a[0] || a[i] > 0 && a[i] < a[0]);
32             }
33             else
34             {
35                 cnt += (a[i] > 0 && a[i] < abs(a[0]) || a[i] < 0 && a[i] < a[0]);
36             }
37         }
38         cout << cnt << endl;
39     }
40     return 0;
41 }

 

蓝桥杯 蚂蚁感冒

标签:iostream   logs   ++   clu   else   abs   蚂蚁感冒   bsp   std   

原文地址:http://www.cnblogs.com/wangyiming/p/6661426.html

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