洛谷 P1367 蚂蚁
2015-06-13 21:46
267 查看
题目:http://www.luogu.org/problem/show?pid=1367#
分析:碰头相当于穿过
代码:
分析:碰头相当于穿过
代码:
#include <cstdio> #include <algorithm> using namespace std; const int Tmax=100005; struct node{ int x,d,num; }; node ant[Tmax]; int n,m,position[Tmax]; bool cmp1(const node &a,const node &b) { return a.x<b.x; } int main() { int i; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) { scanf("%d %d",&ant[i].x,&ant[i].d); ant[i].num=i; } sort(ant+1,ant+1+n,cmp1); for(i=1;i<=n;i++){ position[ant[i].num]=i; ant[i].x+=ant[i].d*m; } sort(ant+1,ant+1+n,cmp1); for(i=1;i<=n;i++) if(ant[i].x==ant[i+1].x) ant[i+1].d=ant[i].d=0; for(i=1;i<=n;i++) printf("%d %d\n",ant[position[i]].x,ant[position[i]].d); return 0; }
相关文章推荐
- NOIP2014 寻找道路
- mac下最简单的git安装,配置,操作
- HDU 5269 && BestCoder #44 1002 ZYB loves Xor I (分治)
- NOIP2014 联合权值
- 字典树 hdu5269 ZYB loves Xor I
- gtest 学习之四 testing::Test
- springmvc 开涛 生产者/消费者
- NOIP2011 一元三次方程求解
- TFS域账户手动同步
- 实现301重定向、图片防盗的功能
- string char* char[]的转换
- Mysql添加索引(phpMyadmin)
- 哈希(4) - 求两个链表的交集(intersection)以及并集(union)
- 实现winform下的简单截图
- 单片机之定时器
- Mysql的MySqlDataReader对于MysqlConnection是独占式
- 函数调用方式介绍
- kernel: iwlwifi 0000:04:00.0: Direct firmware load for iwlwifi-7260-13.ucode failed with error -2
- 洛谷P1379 八数码难题
- hdu 5269 ZYB loves Xor I