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 ...
随机推荐
- 记一道C语言编程题(C语言学习笔记)
题目如下 解答如下 #include <stdio.h> #include<math.h> double Mysqrt(double n) { return sqrt(n); ...
- RWCTF2020 DBaaSadge 复现
数据库题目 2020RWCTF DBaaSadge WP 这是一个很有意思的题目,难到让我绝望,跟着大佬smity的思路跑一下,求大佬抱抱. https://mp.weixin.qq.com/s/jv ...
- ORA-00054: 資源正被使用中, 請設定 NOWAIT 來取得它, 否則逾時到期
1.查看被使用资源的OBJECT_ID SELECT *FROM DBA_OBJECTS WHERE OBJECT_NAME='OBJECT_NAME' 2.查看资源被谁占用SELECT * FROM ...
- Vue项目之实现登录功能的表单验证!
Vue项目之实现登录功能的表单验证! 步骤: 配置 Form表单验证; 1.必须给el-from组件绑定model 为表单数据对象 2 给需要验证的表单项 el-form-item 绑定 prop 属 ...
- pycharm安装完成后的一些基本设置
1.设置背景色 file-->Setting-->Appearance&Behavior-->Appearance 2.设置主题 settings --> editor ...
- Springboot中mybatis控制台打印sql语句
Springboot中mybatis控制台打印sql语句 https://www.jianshu.com/p/3cfe5f6e9174 https://www.jianshu.com/go-wild? ...
- Socket的用法——NIO包下SocketChannel的用法 ———————————————— 版权声明:本文为CSDN博主「茶_小哥」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/ycgslh/article/details/79604074
服务端代码实现如下,其中包括一个静态内部类Handler来作为处理器,处理不同的操作.注意在遍历选择键集合时,没处理完一个操作,要将该请求在集合中移除./*模拟服务端-nio-Socket实现*/pu ...
- I/O 复用 multiplexing data race 同步 coroutine 协程
小结: 1.A file descriptor is considered ready if it is possible to perform the corresponding I/O opera ...
- Dubbo 总结:关于 Dubbo 的重要知识点
一 重要的概念 1.1 什么是 Dubbo? Apache Dubbo (incubating) |ˈdʌbəʊ| 是一款高性能.轻量级的开源Java RPC 框架,它提供了三大核心能力:面向接口的远 ...
- Typora使用与GItHhub图床配置
Typora使用 (windows) 1 快捷键 1.1 表格 快捷方式:CTRL+T ID name year 1 Oracle 10 2 Mysql 10 3 Postgresql 20 1.2 ...