AcWing 1211. 蚂蚁感冒
原题链接
简单
作者:
牛奶小柒Luke
,
2021-03-24 20:42:13
,
所有人可见
,
阅读 210
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 55;
int n;
int x[N];
int main(){
cin >> n;
for(int i = 0;i < n;++i) cin >> x[i];
int left = 0,right = 0;
for(int i = 1;i <= n;++i){
if(abs(x[i]) < abs(x[0]) && x[i] > 0) left++;
else if(abs(x[i]) > abs(x[0]) && x[i] < 0) right++;
}
if(left == 0 && x[0] < 0 || right == 0 && x[0] > 0) cout << 1 << endl;
else cout << right + left + 1 << endl;
return 0;
}
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
bool cold[100] = {0,1};
double d[100];
int finish,ant_count,ans = 1;
int main(){
cin >> ant_count;
for(int i = 1;i <= ant_count;++i) cin >> d[i];
while(finish < ant_count){
finish = 0;
for(int i = 1;i <= ant_count;++i){
if(abs(d[i]) <= 0 || abs(d[i]) >= 100) finish++;
}
for(int i = 1;i <= ant_count;++i){
if(d[i] != 0 && d[i] != 100) d[i] += 0.5;
}
for(int i = 1;i <= ant_count;++i){
if(d[i] != 0 && d[i] != 100){
for(int j = i + 1;j <= ant_count;++j){
if(d[j] != 0 && d[j] != 100){
if(abs(d[j]) == abs(d[i])){
d[j] = -d[j],d[i] = -d[i];
if(cold[i] && !cold[j]){
ans++;
cold[j] = 1;
}
if(cold[j] && !cold[i]){
ans++;
cold[i] = 1;
}
}
}
}
}
}
}
cout << ans << endl;
return 0;
}