这场题目除了最后一题稍微难了点,其他都是1眼题。

T1 Bike Tour

没啥好说的,一个循环解决。

T2 Bus Routes

没啥好说的,从第\(n\)的车站开始贪心取最晚的。

T3 Robot Path Decoding

这题也算有点意思吧,但是其实还是挺简单的,大概思路就是用栈模拟一下。

具体步骤

记当前位置位于\(<x, y>\),用栈维护一个\(<dx, dy>\)的序列,表示下一步在两个方向的移动距离。

如果没有数字和括号,这个就是遍历一遍的事情。如果存在数字和括号,就把数字和括号处理掉,然后问题就又变成了遍历一遍的事情了。那么怎么把数字和括号处理掉呢?可以用一个类似括号匹配的过程处理。

  • 如果读到数字,就把\(<number, INVALID>\)压入栈中。INVALID用于表示这是个数字。
  • 如果读到字母,就把对应的移动距离压入栈中。
  • 如果读到右括号,就不断把栈顶元素拿出,直到拿出的元素是数字。
    • 如果是数字,那么把这一段总的移动距离乘上这个数字,再将这一段总的移动距离压入栈中。
    • 如果是\(<dx, dy>\),那么就把这个点的贡献加到这一段的移动距离上。

T4 Wandering Robot

这题有点意思,就额外写一篇博客把。

T3 AC代码

#include <bits/stdc++.h>
using namespace std; // #include <ext/rope>
// using namespace __gnu_cxx; // #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds; // typedef ll key_type;
// typedef null_mapped_type value_type;
// typedef tree<key_type, value_type, less<key_type>, rb_tree_tag, tree_order_statistics_node_update> rbtree; // typedef __gnu_pbds::priority_queue<pi,greater<pi>,pairing_heap_tag > heap; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int l,int r){return l+rng()%(r-l+1);} typedef long long ll;
typedef double db;
typedef pair<int,int> PI;
typedef vector<int> VI; #define rep(i,_,__) for (int i=_; i<=__; ++i)
#define per(i,_,__) for (int i=_; i>= __; --i) #define pb push_back
#define mp make_pair
#define fi first
#define se second
#define x1 _x
#define x2 __x
#define y1 _y
#define y2 __y
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define endl '\n' const double pi = acos(-1.0); namespace IO{
bool REOF = 1; //为0表示文件结尾
inline char nc() {
static char buf[1 << 20], *p1 = buf, *p2 = buf;
return p1 == p2 && REOF && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? (REOF = 0, EOF) : *p1++;
} template<class T>
inline bool read(T &x) {
char c = nc();bool f = 0; x = 0;
while (c<'0' || c>'9')c == '-' && (f = 1), c = nc();
while (c >= '0'&&c <= '9')x = (x << 3) + (x << 1) + (c ^ 48), c = nc();
if(f)x=-x;
return REOF;
} template<class T>
inline void write(T x){
if(x > 9) write(x / 10);
putchar('0'+x%10);
} template<typename T, typename... T2>
inline bool read(T &x, T2 &... rest) {
read(x);
return read(rest...);
} inline bool need(char &c) { return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || (c==')') || (c=='('); }
// inline bool need(char &c) { return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || c==' '; } inline bool read_str(char *a) {
while ((*a = nc()) && need(*a) && REOF)++a; *a = '\0';
return REOF;
} inline bool read_db(double &x){
bool f = 0; char ch = nc(); x = 0;
while(ch<'0'||ch>'9') {f|=(ch=='-');ch=nc();}
while(ch>='0'&&ch<='9'){x=x*10.0+(ch^48);ch=nc();}
if(ch == '.') {
double tmp = 1; ch = nc();
while(ch>='0'&&ch<='9'){tmp=tmp/10.0;x=x+tmp*(ch^48);ch=nc();}
}
if(f)x=-x;
return REOF;
} template<class TH>
inline void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; } template<class TH, class... TA>
inline void _dbg(const char *sdbg, TH h, TA... a) {
while(*sdbg!=',')cerr<<*sdbg++;
cerr<<'='<<h<<','<<' '; _dbg(sdbg+1, a...);
} template<class T>
ostream &operator<<(ostream& os, vector<T> V) {
os << "[ "; for (auto vv : V) os << vv << ","; return os << " ]";
} template<class T>
ostream &operator<<(ostream& os, set<T> V) {
os << "[ "; for (auto vv : V) os << vv << ","; return os << " ]";
} template<class T>
ostream &operator<<(ostream& os, map<T,T> V) {
os << "[ "; for (auto vv : V) os << vv << ","; return os << " ]";
} template<class L, class R>
ostream &operator<<(ostream &os, pair<L,R> P) {
return os << "(" << P.x << "," << P.y << ")";
} #ifdef BACKLIGHT
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...)
#endif
} using namespace IO;
const int N = 2e5 + 5;
const int M = 5e5 + 5;
const int MAXV = 1e6 + 5;
const int MOD = 1e9; // 998244353 1e9+7
const int INF = 0x3f3f3f3f; // 1e9+7 0x3f3f3f3f
const ll LLINF = 0x3f3f3f3f3f3f3f3f; // 1e18+9 0x3f3f3f3f3f3f3f3f
const double eps = 1e-8; // int dx[4] = { 0, 1, 0, -1 };
// int dx[8] = { 1, 0, -1, 1, -1, 1, 0, -1 };
// int dy[4] = { 1, 0, -1, 0 };
// int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }; // ll qp(ll a, ll b) {
// ll res = 1;
// a %= mod;
// assert(b >= 0);
// while(b){
// if(b&1)
// res = res * a % mod;
// a = a * a % mod;
// b >>= 1;
// }
// return res;
// }
// ll inv(ll x) {return qp(x, mod - 2);}
// ll factor[N], finv[N];
// void init() {
// factor[0]=1;
// for(int i=1; i<N; i++) factor[i] = factor[i-1] * i % mod;
// finv[N-1] = qp(factor[N-1], mod - 2);
// for(int i=N-2; i>=0; i--) finv[i] = finv[i+1] * (i+1) % mod;
// }
// ll c(ll n, ll m) {
// return factor[n] * finv[m] % mod * finv[n-m] % mod;
// } // #define ls (x<<1)
// #define rs (x<<1|1)
// #define mid ((l+r)>>1)
// #define lson ls,l,mid
// #define rson rs,mid+1,r // #define fore(_, __) for(int _ = head[__]; _; _=e[_].nxt)
// int head[N], tot = 1;
// struct Edge {
// int v, nxt;
// Edge(){}
// Edge(int _v, int _nxt):v(_v), nxt(_nxt) {}
// }e[N << 1];
// void addedge(int u, int v) {
// e[tot] = Edge(v, head[u]); head[u] = tot++;
// e[tot] = Edge(u, head[v]); head[v] = tot++;
// } /**
* ********** Backlight **********
* 仔细读题
* 注意边界条件
* 记得注释输入流重定向
* 没有思路就试试逆向思维
* 我不打了,能不能把我的分还给我
*/ int n;
char s[2005];
void solve(int Case) {
read_str(s+1); n = strlen(s+1);
stack<pair<ll,ll> > stk;
rep(i, 1, n) {
if(s[i]>='2' && s[i]<='9') {
stk.push(mp(s[i]-'0', INF));
continue;
}
if(s[i] == '(') continue;
if(s[i] == 'N') {
stk.push(mp(MOD-1, 0));
continue;
}
if(s[i] == 'S') {
stk.push(mp(1, 0));
continue;
}
if(s[i] == 'E') {
stk.push(mp(0, 1));
continue;
}
if(s[i] == 'W') {
stk.push(mp(0, MOD-1));
continue;
}
if(s[i]==')') {
ll dx = 0, dy = 0;
while(!stk.empty()) {
pair<ll, ll> p = stk.top(); stk.pop();
if(p.se == INF) {
dx = dx * p.fi % MOD;
dy = dy * p.fi % MOD;
stk.push(mp(dx, dy));
break;
}
else {
dx = ((dx + p.fi) % MOD + MOD) % MOD;
dy = ((dy + p.se) % MOD + MOD) % MOD;
}
}
}
} ll x = 0, y = 0;
while(!stk.empty()) {
pair<ll, ll> p = stk.top(); stk.pop();
x = ((x + p.fi) % MOD + MOD) % MOD;
y = ((y + p.se) % MOD + MOD) % MOD;
} printf("Case #%d: %lld %lld\n", Case, y+1, x+1);
} int main()
{
#ifdef BACKLIGHT
freopen("in.txt", "r", stdin);
#endif
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int _T; read(_T); for (int _ = 1; _ <= _T; _++) solve(_);
// int _T=1; while(read(n)) solve(_T), _T++;
// solve(1);
return 0;
}

Google Kick Start 2020 Round B T1-3的更多相关文章

  1. Google Kick Start 2020 Round C

    ac代码 A. Countdown for循环跑一跑,没啥好说的. B. Stable Wall 如果\(s_{i,j} \ne s_{i+1,j}\),那么说明\(s_{i+1,j}\)必须在\(s ...

  2. Google Kick Start 2020 Round B T4 Wandering Robot

    题意 一个\(n \times m\)的矩形空间,起点是\((1,1)\),终点是\((n,m)\). 假设当前位于\((x,y)\): 如果当前位于最后一行,那么下一步只能走向\((x,y+1)\) ...

  3. Google Kick Start Round G 2019

    Google Kick Start Round G 2019 Book Reading 暴力,没啥好说的 #include<bits/stdc++.h> using namespace s ...

  4. Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解

    Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解 题目地址:https://codingcompetitions.withgoogle.com/kickstar ...

  5. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  6. Google Code Jam 2010 Round 1C Problem A. Rope Intranet

    Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...

  7. Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks

    https://code.google.com/codejam/contest/635101/dashboard#s=p1   Problem A flock of chickens are runn ...

  8. kick start 2019 round D T3题解

    ---恢复内容开始--- 题目大意:共有N个房子,每个房子都有各自的坐标X[i],占据每个房子需要一定花费C[i].现在需要选择K个房子作为仓库,1个房子作为商店(与题目不同,概念一样),由于仓库到房 ...

  9. dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes

    Problem B. Infinite House of Pancakes Problem's Link:   https://code.google.com/codejam/contest/6224 ...

随机推荐

  1. 03-注释与API文档

    1.注释:Comment分类: 单行注释:// 多行注释:/* */ 文档注释:/** */作用: ① 对所写的程序进行解释说明,增强可读性.方便自己,方便别人 ② 调试所写的代码特点: ①单行注释和 ...

  2. 【编写程序中经常犯的一些错误】 Python | 面向对象(一)

    [编写程序中经常犯的一些错误]Python | 面向对象(一) 在学习Python的面向对象这一部分时,经常出现以下错误: 这是错误范例,请仔细甄别: class Person: def __int_ ...

  3. python7.3客户端、服务端的建立

    import socket #创建客户端client=socket.socket() #生成socket连接对象client.connect("localhost",6969) # ...

  4. 文档写作利器:Markdown

    大佬的文章,写的很好,里面推荐的Markdown编辑工具很不错,值的推荐. 文档写作利器:Markdown_网络_xcbeyond|疯狂源自梦想,技术成就辉煌-CSDN博客https://blog.c ...

  5. Python玩转各种多媒体,视频、音频到图片

    我们经常会遇到一些对于多媒体文件修改的操作,像是对视频文件的操作:视频剪辑.字幕编辑.分离音频.视频音频混流等.又比如对音频文件的操作:音频剪辑,音频格式转换.再比如我们最常用的图片文件,格式转换.各 ...

  6. java_线程、同步、线程池

    线程 Java使用 java.lang.Thread 类代表线程,所有的线程对象都必须是Thread类或其子类的实例 Thread类常用方法 构造方法 public Thread():分配一个新的线程 ...

  7. C# Thread.Name 的作用和意义

    Thread.Name属性 C#的线程提供Thread.Name属性.这意味着每个线程可以设定一个Name属性来标志它们. Name属性的使用时特性 线程的Name属性默认情况下是null.该值只能被 ...

  8. Java多线程编程(6)--线程间通信(下)

      因为本文的内容大部分是以生产者/消费者模式来进行讲解和举例的,所以在开始学习本文介绍的几种线程间的通信方式之前,我们先来熟悉一下生产者/消费者模式.   在实际的软件开发过程中,经常会碰到如下场景 ...

  9. X86汇编——计算斐波那契数列程序(详细注释和流程图说明)

    X86汇编实现斐波那契数列 程序说明: 输入斐波那契数列的项数, 然后依次输出斐波那契数列, 输入的项数小于256且为数字, 计算的项数不能超过2^16次方, 输入失败是 不会回显数字 因为存结果是A ...

  10. 看DLI服务4核心如何提升云服务自动化运维

    摘要:今天我们来说说DLI是如何实现监控告警来提升整体运维能力,从而为客户更好的提供Serverless的DLI. DLI是支持多模引擎的Serverless大数据计算服务,免运维也是其作为Serve ...