链接:https://ac.nowcoder.com/acm/contest/338/A
来源:牛客网

题目描述

AFei is a trainee magician who likes to study various magical materials. Today, he came to the forest to find rare materials. He was so lucky that he found a piece of high-level magic stone. He knew that this stone always appeared in the pile, so there must be more nearby. Then he went deeper.
As expected, he found many magic stones. These stones were arranged in a row. Just as he was ready to pick up one, a magical circle was triggered. He was petrified and the stones began to move. As mentioned above, the stones were lined up. Now, some stones moved to one end of the line and the other stones moved to the other end. Stones would not change direction of movement unless they collided with other stones. Collision meant that two stones moved to the same position, and then the directions of the two stones would both change. Whether or not a collision occured, the speed was always 1 m/s. Stone would disappear when it reached one of the ends.
AFei knew that the magical circle would disappear after t seconds. It meant that after t seconds, he could move and the stones would return to immobility. This also meant that AFei would get those stones. He wondered how many magic stones he could get in the end, including the first one he got when he came to the forest.

输入描述:

The first line contains three integers n, L, t (0≤n≤1000000, 2≤L≤1000000000, 0<=t<=1000000) − the number of stones on the line is n,the length of the line is L meter, and the magic circle will disappear after t seconds.
The following n lines contain description of magic stones on the line. Each i-th of these lines contains two space-separated integers x[i] and d[i] (0<x[i]<L, d[i]∈{1,2} for i<=n), which stand for initial position and direction of motion(1 means from 0 to L, 2 means from L to 0.).

输出描述:

Output a number indicating the amount of the magic stones that AFei will eventually be able to obtain.
示例1

输入

复制

0 10000 3

输出

复制

1

说明

There is no magic stone on the line, but AFei has got one  when he came to the forest.
示例2

输入

复制

4 10 6
1 1
5 2
6 1
9 2

输出

复制

3

说明

The stones are A(1,1), B(5,2), C(6,1), D(9,2).

After 1s, they become A(2,1), B(4,2), C(7,1), D(8,2);

After 2s, they become A(3,2), B(3,1), C(7,2), D(8,1);

After 3s, they become A(2,2), B(4,1), C(6,2), D(9,1);

After 4s, they become A(1,2), B(5,2), C(5,1), D reach L and disappears;

After 5s, they become A reach 0 and disappears, B(4, 2), C(6,1), D disappeared;

After 6s, they become A disappeared, B(3, 2), C(7, 1), D disappeared.

AFei finially gets the first one, B and C.

备注:

1,Input guarantees that there will not be two magic stones in one location.

2,If stone A and stone B are located at 4 and 5, respectively, and A's direction is 1, B's direction is 2. Then next second, the position of the two stones have not changed, but they have gone in the opposite direction.

解题思路:不考虑碰撞,直接根据初始坐标,方向,时间和速度求出每一个魔法石的最终坐标,最终坐标在(0,L)的魔法石数量就是剩下的魔法石
#include<stdio.h>
int main()
{
int n ;
int len, t;
int a,b; while(scanf("%d%d%d",&n,&len,&t)!=EOF)
{
int sum = 1;
for(int i = 0; i<n; i++)
{
scanf("%d %d",&a,&b);
if(b == 1)
{
if(a+t<len)
sum++; }
else
{ if(a-t>0)
sum++;
}
}
printf("%d\n",sum);
} }

A AFei Loves Magic的更多相关文章

  1. 湖南大学第十四届ACM程序设计新生杯(重现赛)

    RANK  0 题数 0 期末复习没有参加,补几道喜欢的题. A: AFei Loves Magic  签到 思路 :不需考虑 碰撞 直接计算最终状态即可. #include<bits/stdc ...

  2. Little Elephant and Magic Square

    Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains s ...

  3. F Find the AFei Numbers

    链接:https://ac.nowcoder.com/acm/contest/338/F来源:牛客网 题目描述 AFei loves numbers. He defines the natural n ...

  4. CodeForces-259B]Little Elephant and Magic Square

      Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains ...

  5. BestCoder Round #90

    有生以来第一场在COGS以外的地方打的比赛.挂成dog了. 主要是没有经验,加之代码能力过弱.还有最后的瞎hack三次,Too Young Too Simple...... 言归正传. (抄一发题解先 ...

  6. codeforces259B

    Little Elephant and Magic Square CodeForces - 259B Little Elephant loves magic squares very much. A  ...

  7. 【Codeforces717F】Heroes of Making Magic III 线段树 + 找规律

    F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes inpu ...

  8. HDU4876ZCC loves cards(多校题)

    ZCC loves cards Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...

  9. 多校训练赛2 ZCC loves cards

    ZCC loves cards Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

随机推荐

  1. MacBook Pro修改hosts

    访达前往:/etc/hosts 将hosts复制到桌面修改保存 替换 附Windows hosts文件位置: C:\windows\System32\drivers\etc

  2. Altium Designer设计PCB中如何开槽

    在不同层画槽孔形状实际得到的PCB效果(注意槽孔边缘) 在不同层画槽孔形状进行(注意槽孔边缘) 很多坛友问在使用Altium Designer设计PCB时,想在板子上开一个槽或者挖一个孔该如何操作,是 ...

  3. 编译安装github上的kafka_exporter项目

    本文介绍的kafka_exporter是prometheus监控系统中针对kafka的一款监控插件,要使用这个监控插件,kafka的版本需要满足 0.10.1.0 及以上. 项目的github地址:h ...

  4. 【学习】008 Socket网络编程

    课程目标 网络模型 TCP协议与UDP协议区别 Http协议底层实现原理. 什么是网络模型 网络编程的本质是两个设备之间的数据交换,当然,在计算机网络中,设备主要指计算机.数据传递本身没有多大的难度, ...

  5. 2018-08-15-weekly

    Algorithm 5. Longest Palindromic Substring What 给定一个字符串s,找到s中最长的回文子字符串. 给定s的最大长度为1000. How 这是一道比较经典的 ...

  6. Python实例教程

    转自:http://codingdict.com/article/9026 Python 100例-01 题目: 输有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数? Python 1 ...

  7. OC + RAC (八) 查看信号状态和跳过信号

    -(void)_test9{ /// RACCommand又叫命令 是用来收发数据的 监听按钮点击,网络请求.... RACCommand * command = [[RACCommand alloc ...

  8. Python_002(基础知识)

    1.格式化输出 %s:字符串的占位符,可以放置任何内容(数字) 代码展示:%去除法 admin_input1 = input("请输入用户名:") pass_input = inp ...

  9. web css

    CSS圆角——透明圆角化背景图片 序言:第一章中我介绍了最基本的纯CSS圆角框的实现原理,并给出Demo,在本章中会对上一个模型作一些新的创新,实现将背景图片透明圆角化.并给出一些漂亮的通用演示效果. ...

  10. CSS3中哪些新属性—阴影、文本省略(1)

    CSS3中的阴影,我知道的就是盒阴影和文字阴影.两者使用大同小异. 1.文字阴影 不知道为啥阴影会被开发出来,觉得这没啥好用啊.用了之后发现好像还行,使页面更有立体感了那么一点点.看起来趣味性强一点. ...