2018 计蒜之道 初赛 第二场

签到完看到C没什么人过就溜乐。

A.淘宝的推荐系统

直接DP,时间复杂度$O(∑nd)$

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)
#define MP		make_pair
#define fi		first
#define se		second

typedef long long LL;

const int N = 2e5 + 10;

int f[N];
int T;
int ans;
int n, d;

int main(){

	scanf("%d", &T);
	while (T--){
		scanf("%d%d", &n, &d);
		memset(f, 0, sizeof f);

		ans = 0;

		rep(i, 1, n){
			int x;
			scanf("%d", &x);
			int mx = 0;
			rep(j, x - d, x + d){
				if (j > 0) mx = max(mx, f[j]);
			}

			f[x] = max(f[x], mx + 1);
			ans = max(ans, f[x]);
		}

		printf("%d\n", ans);
	}

	return 0;
}

B.阿里巴巴的手机代理商(简单)

map直接暴力。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)
#define MP		make_pair
#define fi		first
#define se		second

typedef long long LL;

map <string, int> mp;

int T;
int n;
string op, ss, s;

int main(){

	std::ios::sync_with_stdio(false);

	cin >> T;

	while (T--){
		cin >> n;
		mp.clear();

		rep(i, 1, n){
			cin >> op;
			if (op[0] == ‘i‘){
				int y;
				cin >> ss >> y;
				mp[ss] += y;
			}

			else if (op[0] == ‘q‘){
				cin >> ss;

				int len = ss.length();

				int ans = 0;

				for (auto u : mp){
					string s = u.fi;
					int sz = s.length();
					if (sz < len) continue;

					int fg = 1;
					int p = -1;
					rep(i, sz - len, sz - 1){
						++p;
						if (s[i] != ss[p]){
							fg = 0;
							break;
						}
					}

					if (fg) ans += u.se;
				}
				cout << ans << endl;
			}

			else if (op[0] == ‘d‘){

				cin >> ss;
				if (mp[ss] == 0) cout << "Empty" << endl;
				mp[ss] = 0;
			}
		}
	}

	return 0;
}

C.阿里巴巴的手机代理商(中等)

看起来好像是个字典树上的模拟……待补

D. 阿里巴巴的手机代理商(困难)

留坑。听zlc1114说是……暴力?

原文地址:https://www.cnblogs.com/cxhscst2/p/9034044.html

时间: 2024-08-12 16:40:04

2018 计蒜之道 初赛 第二场的相关文章

2017计蒜之道 初赛 第二场 百度的科学计算器(简单)

/** 题目:2017计蒜之道 初赛 第二场 百度的科学计算器(简单) 链接:https://nanti.jisuanke.com/t/15504 题意:给一个合法的表达式,包含加号+.减号-.括号().数字常量,表达式中没有空格. 输入数据保证数字常量以及计算过程中数值绝对值均不超过 10^12??,对于浮点型数值常量,保证小数点后不超过 666 位. 思路:暴力模拟:python有函数可以直接调用. 坑点:如果表达式中出现过浮点数,那么输出结果保留6位小数, 否则输出整数,不出现小数. */

计蒜之道 初赛 第二场 题解

人人都有极客精神 人人公司是一家极为鼓励极客精神的公司,当有重要的项目需要上线但又时间太紧,甚至需要当天上线的时候,往往会挂起海盗旗开启电子日期显示,让大家可以在对时间有更明确的感知的情况下,同心协力搞定重要的项目.海盗旗下方的电子屏显示的日期形式为 YYYYMMDD (年份占 4 位.月份占 2 位.天数占 2 位). 日期电子屏幕上每个数字对应的显示如下图: <img src="http://res.jisuanke.com/img/nanti/428.png" <=&

2018 计蒜之道 初赛 第一场

百度无人车 二分 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 2e4 + 10; LL a[maxn]; int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%lld", a + i); LL p, s; scanf("

2017 计蒜之道 初赛 第一场 B.阿里天池的新任务

2017 计蒜之道 初赛 第一场 B.阿里天池的新任务 1 /* QYP kuai wo dai ma*/ 2 #include<algorithm> 3 #include<iostream> 4 #include<iomanip> 5 #include<cstring> 6 #include<cstdlib> 7 #include<cstdio> 8 #include<queue> 9 #include<ctime

2018 计蒜之道 初赛 第三场

A. 贝壳找房性价比 题解:按s排序后,斜率最大的点必定在相邻的两点之间. #pragma warning(disable:4996) #include<queue> #include<map> #include<string> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #de

2018 计蒜之道 初赛 第五场

这次的比赛没有现场打,而是等到了今天才来补. 主要是因为那时候和HHHOJ上的比赛冲突了,所以就没写. 这次前三题的难度都比较低,但是就是一个T4要莫比乌斯反演.又是不可食用的. 好了我们开始看题. A. 贝壳找房搬家 这道题刚开始看的时候没看懂题意,觉得T1就是这种立体几何的题目,有种想死的感觉. 因为我认为这个方块可以不规则地想怎么放就怎么放的,其实题目中有一句话: 我们可以把这堆箱子看成一个\(x \times y \times z\) 的长方体. 什么?刚开始只能是长方体吗?好吧好像还是

计蒜之道 初赛第一场B 阿里天池的新任务(简单)

阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次. 首先,定义一个序列 ww: \displaystyle w_{i} = \begin{cases}b, & i = 0\\(w_{i-1} + a) \mod n, & i > 0\end{cases}w?i??={?b,?(w?i−1??+a)modn,???i=0?i>0?? 接下来,定义长度为 nn 的 DNA 碱

2017 计蒜之道 初赛 第一场 A、B题

A题 阿里的新游戏 题目概述: 阿里九游开放平台近日上架了一款新的益智类游戏--成三棋.成三棋是我国非常古老的一个双人棋类游戏,其棋盘如下图所示: 成三棋的棋盘上有很多条线段,只能在线段交叉点上放入棋子.我们可以用坐标系来描述棋盘: 如果一条线段上的三个交叉点都被同一玩家的棋子占据的话,则称这条线段被该玩家 成三.现在,小红和小明两人在游戏平台上下棋,其中小红的棋子是黑色的.请你帮小红计算他成三的线段数. 样例对应的棋盘如下: 输入格式 输入第一行两个整数 n,m(3 \le n, m \le

计蒜之道 初赛 第一场 题解

搜狗输入法的分词算法 搜狗输入法最近的用户输入中出现了一种新的输入模式,形如 "0k1234567",搜狗的工程师发现这一模式后了解到,这是一种新被提出的对于十五进制数字的标记模式,其中 "0k" 是标记进制为15的前缀标记,之后的部分 "1234567" 是实际的十五进制的数字串. 在发现这一标记模式后,搜狗的工程师开始尝试在已有的分词算法上进一步加入对于十五进制数字串的处理,把网页上的这种形式的 15 进制数正确地提取出来.我们知道,标记十五