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) ...
随机推荐
- Taro -- 微信小程序密码弹窗
记录一个类似支付密码的弹窗写法,实现是否免密功能.如图: index.js import Taro, { Component } from '@tarojs/taro' import { Vi ...
- Nginx安装与配置-Centos7
Nginx是一款高性能免费开源网页服务器,也可用于反向代理和负载均衡服务器.该软件由伊戈尔·赛索耶夫于2004年发布,2019年3月11日,Nginx被F5 Networks以6.7亿美元收购.201 ...
- 08Servlet
1.Servlet概念 1.1 servlet的特点 1)sevlet是一个普通的java类,继承HttpServlet类. 2)其实实现了Servlet接口的java类,才是一个Servlet类. ...
- Oracle Set操作
并集合 union/uinon all union 会去重,uinon all 不去重 交集 intersect 差集 minus
- Springboot 默认cache
1:Springboot 默认缓存为ConcurrentMapCacheManager(spring-context) 2:再启动类上开启缓存 @SpringBootApplication //相当于 ...
- 触发写Redo Log的条件
参见:http://www.ixora.com.au/notes/redo_write_triggers.htm http://www.eygle.com/archives/2005/02/redoa ...
- 对logistic回归分析的两重认识
logistic回归,回归给人的直观印象只是要求解一个模型的系数,然后可以预测某个变量的回归值.而logistic回归在应用中多了一层含义,它经常应用于分类中.第一重认识:logistic是给真正的回 ...
- Java泛型与集合笔记
第一章 Java的泛型为了兼容性和防止代码爆炸,在编译成字节碼时会进行类型擦除,编译器自动添加代码做类型转换(用到List<Integer>的地方用Integer来做转换),自动做装箱拆箱 ...
- 微信小程序填坑之路其一:wx.request发送与服务端接受
一.序言 应公司要求要求,要用小程序开发一个信息录入系统.没办法只能听话来填坑. 先介绍一下环境:客户端——小程序:服务端——java:数据库——mysql:服务器——centos7 需求:客户端输入 ...
- 170820-关于JSP页面的知识点
1.JSP [1] 简介 > HTML - HTML擅长显示一个静态的网页,但是不能调用Java程序. > Servlet - Servlet擅长调用Java程序和后台进行交互,但是它不擅 ...