admin管理员组文章数量:1558085
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
struct Ant
{
int pos;
int dir;
};
Ant ant[101];
int pos[101];
int cmp(const void *a, const void *b) {
Ant at = *(Ant *)a;
Ant bt = *(Ant *)b;
return at.pos - bt.pos;
}
int main(int argc, char const *argv[])
{
int n;
//freopen("input.txt","r",stdin);
while(scanf("%d",&n) != EOF) {
for(int i = 0; i < n; i++) {
scanf("%d %d",&ant[i].pos, &ant[i].dir);
}
qsort(ant, n, sizeof(Ant), cmp);
int left = 0;
int right = 0;
int Apos;
int state = 0;
int j = 0;
for(int i = 0; i < n; i++) {
if(state == 0 && ant[i].dir == 1) {
pos[j++] = ant[i].pos;
left++;
}
else if(state == 0 && ant[i].dir == 0) {
state = 1;
Apos = j;
pos[j++] = ant[i].pos;
}
else if(state == 1 && ant[i].dir == -1) {
pos[j++] = ant[i].pos;
right++;
}
}
if(left == right) {
puts("Cannot fall!");
continue;
}
else if(left > right) {
int tmp = left - right;
int ans = 100 - pos[tmp-1];
printf("%d\n",ans);
}
else {
int tmp = right - left;
int ans = pos[Apos + left+1];
printf("%d\n",ans);
}
}
return 0;
}
/**************************************************************
Problem: 1159
User: cust123
Language: C++
Result: Accepted
Time:0 ms
Memory:1520 kb
****************************************************************/
版权声明:本文标题:题目1159:坠落的蚂蚁 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727305469a1107414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论