2020ICPC·小米 网络选拔赛第一场
2020ICPC·小米 网络选拔赛第一场
C-Smart Browser
#include <string>
#include <iostream>
std::string s;
void solve() {
std::cin >> s;
int ans = 0, t = s[0] == 'w';
for (int i = 1; i < s.size(); i++) {
if (s[i] == 'w') {
t++;
} else {
if (t != 0) {
ans += 2 * t - 1;
t = 0;
}
}
}
if (t != 0) {
ans += 2 * t - 1;
}
printf("%d\n" ,ans);
}
int main() {
solve();
return 0;
}
I-Walking Machine
思路:
一道模拟+DFS。对于每个点检查它的四个方向上的点能不能到达这个点,可以的话就DFS。
代码中处理了大量重复片段,一来减小了代码量,二来方便查错,具体细节在代码中体现。
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc sesond
const int Maxn = 1005;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; // W S A D
int a[Maxn][Maxn], n, m, ans = 0;
bool vis[Maxn][Maxn];
inline int read() {
char ch, tar[] = "WSAD";
while ((ch = getchar()) != EOF) {
for (int i = 0; i < 4; i++) {
if (ch == tar[i]) {
return i;
}
}
}
return -1;
}
std::pii getDest(int x, int y) {
int d = a[x][y];
int xx = x + dir[d][0];
int yy = y + dir[d][1];
return std::mp(xx, yy);
}
void run(int x, int y, int xx, int yy);
void dfs(int x, int y) {
for (int i = 0; i < 4; i++) {
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if (xx >= 1 && yy >= 1 && xx <= n && yy <= m) {
run(x, y, xx, yy);
}
}
}
void run(int x, int y, int xx, int yy) {
if (std::mp(x, y) == getDest(xx, yy) && !vis[xx][yy]) {
vis[xx][yy] = true;
ans++;
dfs(xx, yy);
}
}
void solve() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = read();
}
}
for (int i = 1; i <= n; i++) {
run(i, 0, i, 1);
run(i, m + 1, i, m);
}
for (int i = 1; i <= m; i++) {
run(0, i, 1, i);
run(n + 1, i, n, i);
}
printf("%d\n", ans);
}
int main() {
solve();
return 0;
}
A-Intelligent Warehouse
思路:
记忆化搜索。对于每个存在的数字进行一次搜索,而一些数字可能在搜索之前的数字时就被搜索过,那么直接返回之前搜索过的结果即可。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
const int Maxn = 10000005;
int in[Maxn], a[Maxn], cnt[Maxn], maxx;
int dfs(int cur) {
if (cnt[cur] != 0) {
return cnt[cur];
}
int res = a[cur]; // 至少应该包括他自己
for (int i = 2; i * cur <= maxx; i++) {
if (a[i * cur]) {
res = std::max(res, a[cur] + dfs(i * cur));
}
}
cnt[cur] = res;
return res;
}
void solve() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", in + i);
maxx = std::max(maxx, in[i]);
a[in[i]]++;
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans = std::max(ans, dfs(in[i]));
}
printf("%d\n", ans);
}
int main() {
solve();
return 0;
}
2020ICPC·小米 网络选拔赛第一场的更多相关文章
- 2020ICPC·小米 网络选拔赛第一场 A.Intelligent Warehouse (DP)
题意:给你一组数,选一些数出来组成一个排列,使得每个数都能被前一个数整除,求排列的最大元素. 题解:我们先用欧拉筛筛出\(1e7\)的质数,设\(dp[i]\)表示当前选的数都是\(i\)的约数且合法 ...
- 2020ICPC·小米 网络选拔赛第一场 J.Matrix Subtraction (贪心,二维差分)
题意:给一个\(nXm\)的矩阵,可以选取\(aXb\)的子矩阵,使子矩阵中的所有元素减一,问最后是否能使矩阵中所有元素变为\(0\). 题解:首先贪心,我们看最左上角的元素,如果\(g[1][1]\ ...
- hash(2018年CSUST省赛选拔赛第一场B题+hash+字典树)
题目链接:http://csustacm.com:4803/problem/1006 题目: 思路:正如题目一样,本题是一个hash,比赛的时候用的字典树,但是不知道为什么一直RE(听学长说要动态开点 ...
- 2021ICPC网络赛第一场部分题解-The 2021 ICPC Asia Regionals Online Contest (I)
写在前面 本来应该6题的,结果不知道哪个铸币发了H的clar,当即把我们的思路转向三维几何上.当时我们还在想这三维计算几何的正确率有点太高了还在感叹ICPC选手的含金量,直到赛后我才知道这H题的铸币出 ...
- SCOI2010第一场
NOI2010全国青少年信息学奥林匹克竞赛 四川代表队选拔赛 第一场 题目名称 幸运数字 游戏 股票交易 英文代号 luckynumber game trade 时限 2秒 2秒 2秒 输入文件 lu ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...
- Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)
Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...
- 2018中国大学生程序设计竞赛 - 网络选拔赛 1009 - Tree and Permutation 【dfs+树上两点距离和】
Tree and Permutation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛(8/11)
$$2019中国大学生程序设计竞赛(CCPC)\ -\ 网络选拔赛$$ \(A.\hat{} \& \hat{}\) 签到,只把AB都有的位给异或掉 //#pragma comment(lin ...
随机推荐
- springBoot实现redis分布式锁
参考:https://blog.csdn.net/weixin_44634197/article/details/108308395 .. 使用redis的set命令带NX(not exist)参数实 ...
- kubernets之pod简介
一 k8s集群里面的最小单位是pod 1.1 一个较为简单的pod的配置文件 apiverson: api的版本号 kind: 资源的种类 metadata: pod的种类等相关信息 spec: p ...
- Kioptix Level 1
1. 简介 Vulnhub是一个提供各种漏洞环境的靶场平台. 个人学习目的:1,方便学习更多类型漏洞.2,为OSCP做打基础. 下载链接 https://www.vulnhub.com/entry/k ...
- python--or 和 and 表达式
or表达式: 两边为一真一假,返回真: 两边都为假,返回右边: 两边都为真,返回左边: and表达式: 两边为一真一假,返回假: 两边都为假,返回左边: 两边都为真,返回右边:
- Netty的简单Demo
这个demo是通过网上下载: 使用maven构建的: 项目结构: pom.xml: <dependencies> <dependency> <groupId>io. ...
- Linux下利用ifconfig命令查看和操纵网络接口
为了说明这个问题,首先我们需要解释一下在Linux系统下"网络接口"的含义.通俗来讲,Linux中的所谓网络接口就是指本机的网卡,它相当于计算机的一台负责对网络进行收发数据的外设. ...
- innodb引擎的4大特性
一:插入缓冲 二:二次写 三:自适应哈希 四:预读 1.插入缓冲(insert buffer)插入缓冲(Insert Buffer/Change Buffer):提升插入性能,change buffe ...
- 网络编程 — Linux TCP服务端和客户端
1. 服务端 #include <stdlib.h> #include <string.h> #include <errno.h> #include <sig ...
- js12种应该注意的地方
1. == Javascript有两组相等运算符,一组是==和!=,另一组是===和!==.前者只比较值的相等,后者除了值以外,还比较类型是否相同. 请尽量不要使用前一组,永远只使用===和!==.因 ...
- unstable sort
$sort (aggregation) - MongoDB Manual https://docs.mongodb.com/manual/reference/operator/aggregation/ ...