狼与故事的开始

Input

T\le10T≤10

N\le10N≤10

-1000,000,000\le Pa,Pb,X_i,Y_i \le 1000,000,000−1000,000,000≤Pa,Pb,Xi​,Yi​≤1000,000,000

0\le K,k_i \le10000≤K,ki​≤1000

Sample Input 1

2
2 4 100
2
3 1 113
URLRRRUDLRDDULDLUDDUL
0 0 230
UURRRR
-1 3 80
3
0 1 80
DRRLRLDLRU
-1 3 60
UUUDLLUDDDRRRRRRULLDULUD
1 2 90
LRLRDDULRDRRUDLURD

Sample Output 1

2 1

题解：模拟每个商人的路径，用结构体存一下

//
//  main.cpp
//
//
//  Created by Edwin on 2018-12-23.
//
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0×7ffffff
#define EPS 1e-8
#define maxn 1000000+10
#define PI acos(-1.0)
#define pb push_back
using namespace std;
struct nobe
{
int t,kx;
int num;
}p[maxn];

int cmp(nobe a,nobe b)
{
if(a.t<b.t) return 1;
if(a.t==b.t&&a.kx>b.kx) return 1;
return 0;
}
int main()
{
int test,n,m;
cin>>test;
getchar();
while(test--)
{
int px,py,k;
cin>>px>>py>>k;
getchar();
int n;
cin>>n;
getchar();
int flag=1;
for(int i=1;i<=n;i++)
{
p[i].num=i;
int x,y;
cin>>x>>y>>p[i].kx;
getchar();
string a;
getline(cin,a);
if(p[i].kx<k) {p[i].t=2147483644;continue;}
if(x==px&&y==py)
{
p[i].t=0;flag=0;continue;
}
for(int j=1;j<=a.length();j++)
{
//cout<<x<<" "<<y<<endl;
if(a[j-1]=='U') x++;
if(a[j-1]=='D') x--;
if(a[j-1]=='L') y--;
if(a[j-1]=='R') y++;
if(x==px&&y==py)
{
p[i].t=j;flag=0;break;
}
}
}
sort(p+1,p+1+n,cmp);
if(flag) cout<<"-1"<<endl;
else cout<<p[1].num<<endl;
}
return 0;
}


0 评论