Codeforces Round #363 (Div. 2)
A. Launch of Collider
根据字符左移或右移,输出第一次碰撞的位置,不然输出-1
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 #define LL long long 7 char ch[200005]; 8 LL a[200005],ans; 9 int n; 10 bool f=0; 11 int main() 12 { 13 cin>>n; 14 cin>>ch; 15 for(int i=0;i<n;i++) 16 { 17 cin>>a[i]; 18 } 19 ans=1e9; 20 for(int i=1;i<n;i++) 21 { 22 if(ch[i]=='L'&&ch[i-1]=='R') 23 { 24 ans=min(ans,(a[i]-a[i-1])/2 ); 25 f=1; 26 } 27 } 28 if(f) 29 cout<<ans<<endl; 30 else puts("-1"); 31 }
我自倾杯,君且随意