感想
就很讨厌ZX!!
C++ 代码
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
const int N = 60;
double ants[N], pos[110];
int n, finish;
bool cold[N] = {1};
int main()
{
cin >> n;
for(int i = 0; i < n; i ++)
cin >> ants[i];
int res = 1;
while(1)
{
finish = 0;
//先让蚂蚁走!!
for(int i = 0; i < n; i ++)
{
if(fabs(ants[i]) >= 100 || ants[i] == 0)
finish ++;
else ants[i] += 0.5;
}
if(n == finish) break;
//判断蚂蚁碰没碰上
for(int i = 0; i < n; i ++)
{
double pos1 = ants[i];
if(pos1 == 0 || fabs(pos1) >= 100) continue;
for(int j = i + 1; j < n; j ++)
{
double pos2 = ants[j];
if(pos2 == 0 || fabs(pos2) >= 100) continue;
if(fabs(pos1) == fabs(pos2))
{
if(!cold[i] && cold[j])
{
cold[i] = true;
res ++;
// cout << "在" << pos1 <<"位置上" << i << "感冒了" << endl;
}
if(cold[i] && !cold[j])
{
cold[j] = true;
// cout << "在" << pos2 <<"位置上" << j << "感冒了" << endl;
res ++;
}
ants[i] = -ants[i];
ants[j] = -ants[j];
}
}
}
}
cout << res << endl;
}