Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define MAXN 205
- int n, ex, ey;
- struct str
- {
- int x, y;
- string s;
- } arr[MAXN];
- int cnt[MAXN];
- bool ok(){
- int x = 0, y = 0;
- string dir = "R";
- while (1){
- int tx = INT_MAX, ty = INT_MAX;
- int ind = 0;
- string t = "";
- if (x == ex && y == ey) return 1;
- for (int i=1; i<=n + 1; i++){
- if (dir == "R"){
- if (arr[i].x == x && arr[i].x < tx){
- tx = arr[i].x;
- ty = arr[i].y;
- ind = i;
- if (arr[i].s == "/"){
- t = "U";
- }
- else {
- t = "D";
- }
- }
- }
- else if (dir == "L"){
- if (arr[i].x == x && arr[i].x < tx){
- tx = arr[i].x;
- ty = arr[i].y;
- ind = i;
- if (arr[i].s == "/"){
- t = "D";
- }
- else{
- t = "U";
- }
- }
- }
- else if (dir == "U"){
- if (arr[i].y == y && arr[i].y < ty){
- tx = arr[i].x;
- ty = arr[i].y;
- ind = i;
- if (arr[i].s == "/"){
- t = "R";
- }
- else{
- t = "L";
- }
- }
- }
- else{
- if (arr[i].y == y && arr[i].y > ty){
- tx = arr[i].x;
- ty = arr[i].y;
- ind = i;
- if (arr[i].s == "/"){
- t = "L";
- }
- else {
- t = "R";
- }
- }
- }
- }
- cnt[ind]++;
- if (!ind ||cnt[ind] > 2) return 0;
- dir = t;
- if (t == "R"){
- x = tx - 1;
- y = ty;
- }
- else if (t == "L"){
- x = tx - 1;
- y = ty;
- }
- else if (t == "U"){
- x = tx;
- y = ty + 1;
- }
- else{
- x = tx;
- y = ty - 1;
- }
- }
- }
- int main()
- {
- cin >> n >> ex >> ey;
- for (int i=1; i<=n; i++){
- cin >> arr[i].x >> arr[i].y >> arr[i].s;
- }
- arr[n+1].x = ex;
- arr[n+1].y = ey;
- arr[n+1].s = "/";
- if (ok()){
- cout << 0 << "\n";
- return 0;
- }
- for (int i=1; i<=n; i++){
- string temp = arr[i].s;
- if (arr[i].s == "/") arr[i].s = "\\";
- else arr[i].s = "/";
- memset(cnt, 0, sizeof cnt);
- if (ok()){
- cout << i << "\n";
- return 0;
- }
- swap(temp, arr[i].s);
- }
- cout << -1 << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement