计蒜客三场

2023-12-28 08:08
文章标签 计蒜客 三场

本文主要是介绍计蒜客三场,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在腾讯课堂的物理课上,进行了一个有趣的物理实验。

在一个长度为 LL 米的光滑轨道上,小车 A 在 00时刻以 1\mathrm{m/s}1m/s 的速度从左端出发向右运动,小车 B 在 tt 时刻以 1\mathrm{m/s}1m/s 的速度从右端出发向左运动,两个小车的质量相等。假设所有碰撞都是弹性碰撞,也就是当两个小车相向碰撞时,他们各自会以原来的速度向相反的方向运动;小车和轨道两端发生碰撞时,小车会以原速度向反方向运动。

试求出 TT 时刻的时候,两个小车相距多远。

输入格式

输入三个整数 L(1 \le L \le 1000),L(1L1000), t(0 \le t \le 1000),t(0t1000), T(t \le T \le 1000)T(tT1000)

输出格式

输出 TT 时刻两车之间的距离。

样例输入1
10 4 7
样例输出1
0
样例输入2
8 3 9
样例输出2
5

题意:

中文题意,很好明白,不赘述

思路:

对其进行奇偶性分析即可!此处又一新知识点,

t&1这个是与运算,需要将t转换为2进制的数然后t&00000001由于1前面的位数都是0,所以决定结果的就是t的最后一位。如果t是偶数,那么最后一位肯定是0,结果输出0如果t是奇数例如3(0011),那么最后一位肯定是1,结果输出1

代码:




#include <bits/stdc++.h>
using namespace std;
int main()
{int l,a,b;while(cin>>l>>a>>b){swap(a,b);b=a-b;int t=a/l+1;if(t&1)a=a%l;elsea=l-a%l;t=b/l+1;if(t&1)b=l-b%l;else b=b%l;cout<<abs(a-b)<<endl;}return 0;
}


这篇关于计蒜客三场的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/545389

相关文章

计蒜客 Skiing 最长路

In this winter holiday, Bob has a plan for skiing at the mountain resort. This ski resort has MM different ski paths and NN different flags situated at those turning points. The ii-th path from the

计蒜客 Half-consecutive Numbers 暴力打表找规律

The numbers 11, 33, 66, 1010, 1515, 2121, 2828, 3636, 4545 and t_i=\frac{1}{2}i(i+1)t​i​​=​2​​1​​i(i+1), are called half-consecutive. For given NN, find the smallest rr which is no smaller than NN

计蒜客 李白喝酒

感觉这题很有趣,虽然是用来举例二进制的 一天,他提着酒壶,从家里出来,酒壶中有酒两斗。他边走边唱: 无事街上走,提壶去打酒。 逢店加一倍,遇花喝一斗。 一路上,他一共遇到店5次,遇到花10次,已知最后一次遇到的是花,他正好把酒喝光。清计算李白遇到店的和花的次序, 有多少可能的方案。 int ans=0;//方案数 for(int i=0;i<(1<<14);i++){//暴力枚

计蒜客 T1797 最小数和最大数

题目链接:https://nanti.jisuanke.com/t/T1797 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>using namespace std;int main(){int counts;cin>>counts;int t

计蒜客 T1725 国王的魔镜

题目链接:https://nanti.jisuanke.com/t/T1725 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>#include <string>using namespace std;unsigned long minLong

计蒜客 T1677 农场周围的道路

题目链接:https://nanti.jisuanke.com/t/T1677 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>using namespace std;void getGroups(int bulls,int k);int gr

计蒜客 T1560 二分查找(一)

题目链接:https://nanti.jisuanke.com/t/T1560 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>#include <algorithm>using namespace std;long long arr[1000

计蒜客 T1319 质数判定一

题目链接:https://nanti.jisuanke.com/t/T1319 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>#include <math.h>using namespace std;bool isprime(long lon

计蒜客 T1109 字符替换

题目链接:https://nanti.jisuanke.com/t/T1109 https://nanti.jisuanke.com/t/T1109 //// Created by Leo Lee on 2019/4/5.//#include <iostream>#include <string>using namespace std;int main(){string str;cha

计蒜客 T1044 最大数输出

题目链接:https://nanti.jisuanke.com/t/T1044 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) //// Created by Leo Lee on 2019/4/5.//#include <iostream>using namespace std;int main(){int max = INT32_MIN,tmp;for(