湖南大学第十四届ACM新生赛--A--- AFeiLovesMagic

A AFeiLovesMagic

TimeLimit:C/C++1S,JAVA:2SMemoryLimit:C/C++128.000MB,JAVA:256.000MB

题目描述

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.

示例
输入
0 10000 3
输出
1

输入
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.

解:

题意比较简单,石头相撞后各自反向,可以理解成不相撞继续前进,两种情况所得的结果是一样的。
因此我们只需求出在t时间内各个石头是否能移动到最近的边缘。

#include<stdio.h>
int main()
{
	long long m,n,i,j,t,l,a,b,ll,sum=0;
	scanf("%lld%lld%lld",&n,&l,&t);
	for(i=0;i<n;i++)
	{
		scanf("%lld%lld",&a,&b);
		if(b==1) //判断石头移动的方向
		{
			ll=l-a;
			if(ll>t) sum++;
			
		}
		else if(b==2)
		{
			ll=a;
			if(ll>t) sum++;
		}
	}
	printf("%lld",sum+1);
	
 } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值