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) ...
随机推荐
- pandas.DataFrame.drop_duplicates 用法说明
DataFrame.drop_duplicates(subset=None, keep='first', inplace=False) subset考虑重复发生在哪一列,默认考虑所有列,就是在任何一列 ...
- (线性基)Operation
http://acm.hdu.edu.cn/showproblem.php?pid=6579 线性基https://blog.csdn.net/a_forever_dream/article/deta ...
- next_permutation():按字典序输出下一个排列
#include<iostream> #include<algorithm> using namespace std; int main() { int data[4]={5, ...
- [CSP-S模拟测试]:Reverse(模拟+暴力+剪枝)
题目描述 小$G$有一个长度为$n$的$01$串$T$,其中只有$T_S=1$,其余位置都是$0$.现在小$G$可以进行若干次以下操作: $\bullet$选择一个长度为K的连续子串($K$是给定的常 ...
- ReactNative的学习笔记
一.安装nodejs 查看是否安装:npm -v 二.安装react-native命令工具 npm install -g react-native-cli 三.查看 react-native --he ...
- 浅析java中的string
在学习java36讲的时候看到评论区有人提出的一个问题: String s1 = new String("do"); s1.intern(); String s2 = " ...
- php面试专题---9、会话控制考点
php面试专题---9.会话控制考点 一.总结 一句话总结: 面向对象.设计模式这些特别好用,需要融会贯通 1.请写出PHP类权限控制修饰符? public.protected.private 2.p ...
- EZOJ #362历史
分析 就是保存前pi-1个数每个ai出现多少次 然后维护这些数当前剩余的最大值 每次和新加进来的比较即可 如果新的大直接取 否则新的最大值一定不大于原来的最大值 因此o(n) 代码 #include& ...
- 牛客提高D3t1 破碎的矩阵
分析 我们发现如果行的异或和等于列的异或和那么对于n-1行m-1列的所有数的选择都是任意的 因为一定可以在它的行末/列末选一个合适的数是的整体满足 但是我们发现对于右下角那一个数是否满足存疑 我们设矩 ...
- polly的几种常用方法
参考资料:https://www.cnblogs.com/edisonchou/p/9159644.html 特征:可以实现一些代码的熔断和降级 代码: ////普通,其中 Fallback相当于降级 ...