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) ...
随机推荐
- SQL语句分类
SQL Structured Query Language SQL是结构化查询语言,是一种用来操作RDBMS的数据库语言,当前关系型数据库都支持使用SQL语言进行操作,也就是说可以通过 SQL 操作 ...
- 在MySQL登录时出现Access denied for user 'root'@'localhost' (using password: YES) 拒绝访问,并可修改MySQL密码
这两天装了一个mysql 5.7数据库,但是在本地dos登陆不上去,报错Access denied for user 'root'@'localhost'(using password:YES): 也 ...
- Jquery异步上传文件
我想通过jQuery异步上传文件,这是我的HTML: 1 2 3 <span>File</span> <input type="file" id=&q ...
- jmeter性能工具 使用手册(一)
前置条件: 在jmeter官网下载jmter 安装包 电脑有java 环境 使用步骤: 打开jmeter 2.新建线程 Test plan--->add-->theads(users)-- ...
- Feign Dynamic URL
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11811932.html Project Directory Maven Dependency < ...
- 【leetcode】486. Predict the Winner
题目如下: Given an array of scores that are non-negative integers. Player 1 picks one of the numbers fro ...
- django 我的博客 (慕课网视频)笔记
用到的命令 1.创建项目 django-admin startproject myBlog 2.创建appcd [项目名] python3 manage.py startapp blog 3.数据迁移 ...
- windown 使用python 自动切换网络
由于工作环境的特殊性,有时需要切换到内网工作,有时需要通过手机连接外网,想自动运行一个脚本就做完这事 首先在PC机上安装一个无线网卡,例如360wifi就可以. 除了python,还用到了DOS命令, ...
- php 标准库之ArrayObject
以下为ArrayObject的常用函数: ArrayIterator::current( void ) //返回当前数组元素 ArrayIterator::key(void) //返回当前数组key ...
- anki2.1中使用latex,使用 MathJax 渲染latex格式的数学公式,化学公式
说说mathJax的优点: 不在anki媒体库生成图片,有利于节约手机空间. 再说说它的缺点:需要学习latex,需要一些时间去掌握latex语法. 1.去MathJax的github下载源码包 2. ...