Launch of Collider

原创 2016年08月28日 17:53:56

链接:http://codeforces.com/problemset/problem/699/A

题目:

There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.

You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.

Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.



题意:一条直线上有几个点,分别想做或者向右运动,速度均为1m/s,求最早碰撞的时间。

分析:贪心,只有左边的球向右走,右边的球向左走才会碰撞,所以只要找到最小的(RL)间距就是答案。

题解:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
using namespace std;

int n;
char s[200010];
int num[200010];

int main()
{
	//freopen("in.txt", "r", stdin);
	while (cin >> n)
	{
		cin >> s;
		int ans = INT_MAX;
		cin >> num[0];
		for (int i = 1; i < n; i++)
		{
			cin >> num[i];
			if (s[i - 1] == 'R'&&s[i] == 'L')
			{
				ans = min(ans, num[i] - num[i - 1]);
			}
		}
		if (ans < INT_MAX)
			cout << ans/2 << endl;
		else
			cout << "-1" << endl;
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Codeforces-699A Launch of Collider

There will be a launch of a new, powerful and unusual collider very soon, which located along a stra...

Launch of Collider

Description There will be a launch of a new, powerful and unusual collider very soon, which loc...

【Codeforces Round 363 (Div 2) A】【水题】Launch of Collider 机器人最早碰撞时间

A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes ...

【模拟】Codeforces 699A Launch of Collider

题目链接:   http://codeforces.com/problemset/problem/699/A 题目大意:   给N个点,向左或向右运动,速度均为1,问最早什么时候...

Codeforces Round #363(Div. 2) A. Launch of Collider【模拟】 && B. One Bomb【暴力】

Codeforces Round #363(Div. 2) A. Launch of Collider【模拟】 && B. One Bomb【暴力】

Codeforces-Round-#363-Launch of Collider

Codeforces-Round-#363-Launch of Collider

Codeforces #363 (Div.2) A. Launch of Collider【水题】

A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes ...

CodeForces 699A - Launch of Collider(水题)

题目大意:给定n个点,它们分别以1m/s的速度在运动,或左或右。求这些点中,最早发生碰撞所需要的时间,如果不能碰撞,输出-1。第一行输入n,第二行输入粒子的运动方向。第三行输入粒子x坐标。 解题思路:...

【打CF,学算法——一星级】Codeforces 699A Launch of Collider (水题)

【CF简介】 题目链接:CF 699A 题面: A. Launch of Collider time limit per test 2 seconds ...

CodeForces - 699A Launch of Collider 粒子对撞机 基础题

CF传送门 题意: 1. n个粒子排列在正x轴上 2. L,R代表对应粒子的运动方向,每秒运动一个单位 3. 求粒子能相撞的最短时间 4. 如果粒子永远无法相撞,就输出-1 题...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)