A AFei Loves Magic
链接:https://ac.nowcoder.com/acm/contest/338/A
来源:牛客网
题目描述
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.
说明
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的更多相关文章
- 湖南大学第十四届ACM程序设计新生杯(重现赛)
RANK 0 题数 0 期末复习没有参加,补几道喜欢的题. A: AFei Loves Magic 签到 思路 :不需考虑 碰撞 直接计算最终状态即可. #include<bits/stdc ...
- Little Elephant and Magic Square
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains s ...
- F Find the AFei Numbers
链接:https://ac.nowcoder.com/acm/contest/338/F来源:牛客网 题目描述 AFei loves numbers. He defines the natural n ...
- 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 ...
- BestCoder Round #90
有生以来第一场在COGS以外的地方打的比赛.挂成dog了. 主要是没有经验,加之代码能力过弱.还有最后的瞎hack三次,Too Young Too Simple...... 言归正传. (抄一发题解先 ...
- codeforces259B
Little Elephant and Magic Square CodeForces - 259B Little Elephant loves magic squares very much. A ...
- 【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 ...
- HDU4876ZCC loves cards(多校题)
ZCC loves cards Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- 多校训练赛2 ZCC loves cards
ZCC loves cards Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
随机推荐
- Maya2017下载安装与激活
目录 1. 更多推荐 2. 下载地址 2.1. OneDrive 2.2. 百度云 3. 安装激活步骤 1. 更多推荐 其他Maya版本的下载与激活:https://www.cnblogs.com/c ...
- TensorFlow学习笔记1:graph、session和op
graph即tf.Graph(),session即tf.Session(),很多人经常将两者混淆,其实二者完全不是同一个东西. graph定义了计算方式,是一些加减乘除等运算的组合,类似于一个函数.它 ...
- 2019南京网赛 The beautiful values of the palace(思维,树状数组
https://nanti.jisuanke.com/t/41298 题意:给一个n * n的螺旋矩阵,n保证是奇数,取一些点使其.获得价值,价值为数位和,然后再给q次查询,求矩阵中的价值总和 思路: ...
- 覆盖(Override)和重写(Overload)的区别
Overload Overload是重载的意思. 重载Overload表示同一个类中可以有多个名称相同的方法,但这些方法的参数列表各不相同(即参数个数或类型不同). Overload对我们来说可能比较 ...
- hdu 6055 : Regular polygon (2017 多校第二场 1011) 【计算几何】
题目链接 有个结论: 平面坐标系上,坐标为整数的情况下,n个点组成正n边形时,只可能组成正方形. 然后根据这个结论来做. 我是先把所有点按照 x为第一关键字,y为第二关键字 排序,然后枚举向量 (p[ ...
- es6 扩展运算符 三个点...
es6中引入扩展运算符…,它用于把一个数组转化为用逗号分隔的参数序列,它常用在不定参数个数时的函数调用,数组合并等情形.因为typeScript是es6的超集,所以typeScript也支持扩展运算符 ...
- 对Promise的研究3
Promise.race() Promise.race方法同样是将多个 Promise 实例,包装成一个新的 Promise 实例. const p = Promise.race([p1, p2, p ...
- MaxCompute按量计费计算任务消费监控告警
MaxCompute 按量计费资源为弹性伸缩资源,对于计算任务,按任务需求提供所需资源,对资源使用无限制,同时MaxCompute按量计费的账单为天账单,即当天消费需要第二天才出账,因此,有必要对计算 ...
- Queue2链队列
链队列 1 #include <iostream> using namespace std; template <class T> class Queue { private: ...
- 【转】网站出现service unavailable的解决方法
特别提示:本文的教程仅适合采用windows服务器的IIS组件上操作,service unavailable是许多网站会经常遇到的问题,希望对大家有用. 昨天一小段时间网站出现了service una ...