C++
Google kick start 2020 B - Robot Path Decoding

Được viết bởi: Codeforces


Code thuật full


Đề bài: https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc8/00000000002d83dc


// _____ _ _
// / ____| | | (_)
// | (___ ___ _ __ __| | ___ _ __ ______ _ _
// \___ \ / _ \| '_ \ / _ |/ _ \ '_ \ |_ / _ | |
// ____) | (_) | | | | | (_| | __/ |_) | / / (_| | |
// |_____/ \___/|_| |_| \__,_|\___| .__/ /___\__,_|_|
// | |
// |_|

#include <bits/stdc++.h>
#define nmax 100005
#define oo 10000000007
#define mod 1000000000
#define reset(x) memset(x, 0, sizeof x)
#define F first
#define S second
#define sonin cin
#define sonout cout
#define debug(x) cout << "Loli -> " << #x << " : " << x << "\n"
#define debugAry(x, a, b, y) for(int y = a; y<=b; y++) cout << #x << "[" << y << "]" << " -> " << x[y] << "\n"
#define filename ""
#define fileNX freopen(filename".inp", "r", stdin); freopen(filename".out", "w", stdout);
#define fileN freopen(filename".inp", "r", stdin);
#define fileX freopen(filename".out", "w", stdout);
#define toiuuhoa ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(a) (int) a.size()
#define FOU(x,a,b) for (lli x=a;x<=b;x++)
#define FOD(x,a,b) for (lli x=a;x>=b;x--)
#define FOA(a,b) for(auto &a:b)
#define ALLvec(a) a.begin(),a.end()
#define REU(x,a,b) for (lli x=a;x<b;x++)
#define RED(x,a,b) for (lli x=a;x>b;x--)
#define AutoCinAry(a,b,x) for(int a = 1; a<=b; a++) cin >> x[i];
#define dembit1(x) __builtin_popcount(x)
#define bit(x,i) ((x>>(i-1))&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
#define EL cout << "\n";
#define EX exit(0);
#define Ary(x, i, j, a) x[(i - 1) a + j]
#define epsinon 1e-8
#define Son_onii_chan main
#define times double stime = clock();
#define gettime cerr << "Time executed: " << (clock() - stime) / CLOCKS_PER_SEC
1000 << "ms.\n";
using namespace std;
typedef long long lli;
typedef long double ldo;
typedef double dou;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
typedef vector<pii> vpi;
typedef deque<lli> dqll;

lli t;
string s;
//N = top, S = bottom, E = right, W = left
lli xx, yy;
ldo mul;
lli stk[2005], stt;
void UpdatePoint(){
if(xx < 1)
xx += mod;
if(xx > mod)
xx -= mod;
if(yy < 1)
yy += mod;
if(yy > mod)
yy -= mod;
}
bool NoCok = false;
lli NewKKjd = 0;
void PushStack(lli inx){
stk[stt] = inx;
stt++;
NoCok = false;
}
void PopStack(){
stt--;
NoCok = false;
}
lli TopStack(){
return stk[stt-1];
}
lli GGk(){
if(NoCok == true)
return NewKKjd;
NoCok = true;
lli inx = 1;
FOD(i, stt-1, 0){
inx = (inxstk[i])%mod;
}
NewKKjd = inx;
return inx;
}
void MainProcess(){
sonin >> s;
//string number = "";
xx = 1; yy = 1; mul = 1;
stt = 0;
FOU(i,0,s.size()-1){
if(s[i] >= '2' && s[i] <= '9'){
lli getkk = (s[i] - '0');
//mul
= getkk;
PushStack(getkk);
} else if(s[i] == '('){
} else if(s[i] == ')'){
//mul /= TopStack();
PopStack();
} else {
if(s[i] == 'N')
yy -= GGk();
if(s[i] == 'S')
yy += GGk();
if(s[i] == 'W')
xx -= GGk();
if(s[i] == 'E')
xx += GGk();
UpdatePoint();
}
}
sonout << xx << " " << yy;
}
int Son_onii_chan(){
//fileNX
toiuuhoa
sonin >> t;
FOU(tup, 1, t){
sonout << "Case #" << tup << ": ";
MainProcess();
EL
}
return 0;
}

Posted on April 25, 2020 09:09:23 AM


8
Donate free




Đăng nhập để tham gia thảo luận! Hoặc bạn có thể bình luận bằng facebook ở dưới.