打完TC打CF,顺利多了………
这道题是给出粒子个数和运动方向,以及它们的坐标,输出第一次对撞发生时过了几微秒。如果不可能发生碰撞输出“-1”
4
RLRL
2 4 10 20
输出1
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
const int maxn=200020;
struct particle {
LL d,x;
};
particle li[maxn];
vector<int> nn;
int main() {
int n; char c;
bool lf=false; bool rf=false;
scanf ("%I64d",&n); getchar();/*吃掉回车*/
for (int i=0; i<n; i++) {
c=getchar();
if (c=='R') { li[i].d=1; rf=true; }
else {
li[i].d=-1;
if (rf) { lf=true; }
}
}
for (int i=0; i<n; i++) {scanf ("%I64d",&li[i].x);}
if (! (rf&&lf) ) {printf ("-1\n");}//can not meet
else {
LL minn=INFF,ans=INFF;
for (int i=1; i<n; i++) {
if (li[i].d==-1&&li[i-1].d==1) {
ans= (li[i].x-li[i-1].x) /2;
}
minn=min (minn,ans);
}
printf ("%I64d",minn);
}
return 0;
}