题目1159:坠落的蚂蚁
来源:互联网 发布:软件信息服务比赛 编辑:程序博客网 时间:2024/04/27 18:04
#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****************************************************************/
0 0
- 题目1159:坠落的蚂蚁
- 题目1159:坠落的蚂蚁
- 题目1159:坠落的蚂蚁
- 题目1159:坠落的蚂蚁
- 九度 oj 题目1159:坠落的蚂蚁
- poj 1003坠落的蚂蚁
- 九度OJ 1159:坠落的蚂蚁 (模拟、排序)
- 一些有意思的题目之蚂蚁过河
- 某摧残我两次的题目——蚂蚁
- NYOJ题目744蚂蚁的难题(一)(数学,不大懂)
- NYOJ 题目745 蚂蚁的难题(二)(dp)
- NYOJ 题目944 蚂蚁的腿(水题,易错)
- 白羊座,一个坠落于凡间的精灵
- 一个简单的MapView例子。气球坠落
- 坠落凡间的struts2(5)---拦截器
- 为了那永不坠落的梦想...
- 生命中最伟大的光辉,不在于永不坠落,而是坠落后总能再度升起
- 南阳理工OJ_题目745 蚂蚁的难题(二)&&题目983 首尾相连数组的最大子数组和
- 【LeetCode】Swap Nodes in Pairs
- python字符串拼接
- Deep Learning
- 根据前序遍历和中序遍历重构二叉树
- MongoDB安装及基本使用
- 题目1159:坠落的蚂蚁
- Spring HttpMessageConverter 之 Jackson
- oracel decode
- opencv批量读取图片批量保存图片
- 安卓高德地图开发(四)——自定义线路规划(根据地点的经纬度规划线路)
- Centos配置iptables防火墙
- #ifndef#define#endif的用法(整理)
- java基础总结03-java基础语法2
- Ubuntu更改用户登录方式以root登录