「美团 CodeM 资格赛」试题泛做
LibreOJ真是吼啊!
数码
推个式子,把枚举因数转为枚举倍数。然后就发现它是根号分段的。然后每一段算一下就好了。
#include <cstdio>
#include <cstring> #define R register
typedef long long ll;
struct Data {
ll num[];
inline void clear()
{
memset(num, , << );
}
inline Data operator + (const Data &that) const
{
R Data ret; memcpy(ret.num, num, << );
for (R int i = ; i <= ; ++i) ret.num[i] += that.num[i];
return ret;
}
inline void operator += (const Data &that)
{
for (R int i = ; i <= ; ++i) num[i] += that.num[i];
}
inline Data operator - (const Data &that) const
{
R Data ret; memcpy(ret.num, num, << );
for (R int i = ; i <= ; ++i) ret.num[i] -= that.num[i];
return ret;
}
inline void operator *= (const int &that)
{
for (R int i = ; i <= ; ++i) num[i] *= that;
}
} ;
inline Data calc2(R int N)
{
R ll tmp; R Data ret; ret.clear();
for (tmp = ; tmp - <= N; tmp *= )
for (R int i = ; i <= ; ++i)
ret.num[i] += tmp / ;
tmp /= ;
for (R int i = ; i < (N / tmp); ++i) ret.num[i] += tmp;
ret.num[N / tmp] += N % tmp + ;
// printf("calc2(%d) = \n", N);
// for (R int i = 1; i <= 9; ++i) printf("%lld\n", ret.num[i]);
return ret;
}
inline Data calc(R int N)
{
R Data ret; ret.clear();
for (R int i = , j; i <= N; i = j + )
{
j = N / (N / i);
R Data tmp = calc2(j) - calc2(i - );
tmp *= N / i;
ret += tmp;
}
return ret;
}
int main()
{
R int l, r; scanf("%d%d", &l, &r);
R Data ans = calc(r) - calc(l - );
for (R int i = ; i <= ; ++i)
printf("%lld\n", ans.num[i]);
return ;
}
数码
跳格子
预处理出每个点能不能到终点。然后直接暴搜就好了。
#include <cstdio>
#include <cstdlib> #define R register
#define maxn 100010
struct Edge {
Edge *next;
int to;
} *last[maxn], e[maxn << ], *ecnt = e;
inline void link(R int a, R int b)
{
*++ecnt = (Edge) {last[a], b}; last[a] = ecnt;
}
int q[maxn], n, a[maxn], b[maxn];
bool arv[maxn], ins[maxn];
char st[maxn];
void dfs(R int x, R int step)
{
if (!arv[x]) return ;
if (x == n)
{
for (R int i = ; i < step; ++i) printf("%c", st[i]); puts("");
exit();
}
if (ins[x])
{
puts("Infinity!");
exit();
}
ins[x] = ;
if (x + a[x] > && x + a[x] <= n)
{
st[step] = 'a';
dfs(x + a[x], step + );
}
if (x + b[x] > && x + b[x] <= n)
{
st[step] = 'b';
dfs(x + b[x], step + );
}
}
int main()
{
scanf("%d", &n);
for (R int i = ; i <= n; ++i) scanf("%d", a + i), i + a[i] > && i + a[i] <= n ? link(i + a[i], i), : ;
for (R int i = ; i <= n; ++i) scanf("%d", b + i), i + b[i] > && i + b[i] <= n ? link(i + b[i], i), : ;
R int head = , tail = ; arv[q[] = n] = ;
while (head < tail)
{
R int now = q[++head];
for (R Edge *iter = last[now]; iter; iter = iter -> next)
if (!arv[iter -> to]) arv[q[++tail] = iter -> to] = ;
}
if (!arv[]) {puts("No solution!"); return ;}
dfs(, );
return ;
}
跳格子
优惠券
一开始傻逼了,以为只要前缀就好了,后来才发现是区间。。。对于每个不满足的条件的左/右括号扔进一个数据结构里,然后每次遇到问号的时候,去消右端点最近的一个括号。然后这个数据结构用堆就够啦~
#include <cstdio>
#include <vector>
#include <queue> #define R register
#define maxn 500010
int last[maxn], lastt[maxn];
struct Opt {int type, x;} p[maxn];
std::vector<int> v[maxn];
std::priority_queue<int, std::vector<int>, std::greater<int> > q;
int main()
{
R int n, num = ; scanf("%d", &n);
for (R int i = ; i <= n; ++i)
{
char opt[]; scanf("%s", opt);
if (opt[] == 'I')
{
R int x; scanf("%d", &x);
p[i] = (Opt) {, x};
}
if (opt[] == 'O')
{
R int x; scanf("%d", &x);
p[i] = (Opt) {, x};
}
if (opt[] == '?') p[i] = (Opt) {, };
}
for (R int i = ; i <= n; ++i)
{
if (p[i].type == ) continue;
if (lastt[p[i].x] == p[i].type)
{
v[last[p[i].x]].push_back(i);
}
last[p[i].x] = i;
lastt[p[i].x] = p[i].type;
}
for (R int i = ; i < v[].size(); ++i) q.push(v[][i]);
for (R int i = ; i <= n; ++i)
{
for (R int j = ; j < v[i].size(); ++j) q.push(v[i][j]);
if (p[i].type == && !q.empty())
{
R int top = q.top(); q.pop();
if (top < i) return !printf("%d\n", top);
}
}
if (q.empty()) puts("-1");
else printf("%d\n", q.top());
return ;
}
优惠劵
「美团 CodeM 资格赛」试题泛做的更多相关文章
- 「题解」「美团 CodeM 资格赛」跳格子
目录 「题解」「美团 CodeM 资格赛」跳格子 题目描述 考场思路 思路分析及正解代码 「题解」「美团 CodeM 资格赛」跳格子 今天真的考自闭了... \(T1\) 花了 \(2h\) 都没有搞 ...
- 「美团 CodeM 资格赛」跳格子
题目描述 nnn 个格子排成一列,一开始,你在第一个格子,目标为跳到第 n 个格子.在每个格子 i 里面你可以做出两个选择: 选择「a」:向前跳 ai 步. 选择「b」:向前跳 bi 步. 把每步 ...
- LOJ#6085. 「美团 CodeM 资格赛」优惠券(set)
题意 题目链接 Sol 考虑不合法的情况只有两种: 进去了 再次进去 没进去 但是出来了 显然可以用未知记录抵消掉 直接开个set维护一下所有未知记录的位置 最优策略一定是最后一次操作位置的后继 同时 ...
- loj 6085.「美团 CodeM 资格赛」优惠券
题目: 一个有门禁的大楼,初始时里面没有人. 现在有一些人在进出大楼,每个人都有一个唯一的编号.现在有他们进出大楼的记录,但是有些被污染了,只能知道这里有一条记录,具体并不能知道. 一个人只有进大楼, ...
- loj 6084.「美团 CodeM 资格赛」跳格子
题目: link 题解: 尽量走\(a\). 只要保证走\(a\)后到达的点一定可以到终点就可以走. 所以从终点开始\(dfs\)出所有能够到达终点的点. 然后再从起点开始\(dfs\)路径即可. 如 ...
- loj 6083.「美团 CodeM 资格赛」数码
题目: 给定两个整数\(l\)和\(r\),对于任意\(x\),满足\(l\leq x\leq r\),把\(x\)所有约数写下来. 对于每个写下来的数,只保留最高位的那个数码.求\([1,9]\)中 ...
- #6085. 「美团 CodeM 资格赛」优惠券
题目描述 用last[x]表示对x进行的上一次操作的位置,vis[x]表示x是否在大楼内. Splay维护'?'的位置. 若x要进楼: 1.若x已在楼内,则去找last[x]到i之间是否有'?',若有 ...
- [LOJ 6213]「美团 CodeM 决赛」radar
[LOJ 6213]「美团 CodeM 决赛」radar 题意 给定 \(n\) 个横坐标 \(x_i\) , 为它们选择一个不超过 \(y_i\) 的纵坐标 \(h_i\), 产生 \(c_ih_i ...
- LOJ #6192. 「美团 CodeM 复赛」城市网络 (树上倍增)
#6192. 「美团 CodeM 复赛」城市网络 内存限制:64 MiB 时间限制:500 ms 标准输入输出 题目描述 有一个树状的城市网络(即 nnn 个城市由 n−1n-1n−1 条道路连接 ...
随机推荐
- 并不对劲的CF1239B&C&D Programming Task in the Train to Catowice City
CF1239B The World Is Just a Programming Task 题目描述 定义一个括号序列s是优秀的,当且仅当它是以下几种情况的一种: 1.|s|=0 2.s='('+t+' ...
- Java EE javax.servlet中的ServletContext接口
ServletContext接口 public interface ServletContext (https://docs.oracle.com/javaee/7/api/javax/servlet ...
- MySQL 事务、视图、索引
一.事务(Transaction) 1.1 什么是事务? SQL中,事务是指将一系列数据操作捆绑成为一个整体进行统一管理. 如果一个事务执行成功,该事务中进行的所有数据均会提交,称为数据库中的永久组成 ...
- feign发送get请求时用复杂类传参
如题,网上都有做法,只有有些人说的不清楚.而我自己也遇到了其他坑这里记录一下 1.就是网上说的做法: 客户端:application.yml加上配置: feign: httpclient: enabl ...
- vue+ element table如何给指定的单元格添加点击事件?
今天使用vue,以及element-ui这个框架时,发现业务需要在表格里加一个连接跳转,当时立刻打开element的官网,进行查看http://element-cn.eleme.io/#/zh-CN/ ...
- 6 java 笔记
1 java的类通过构造器来创建该类的对象 2 java提供extends关键字来实现子类继承父类 3 初始化块总是在构造器调用之前被执行 4 可以吧java中的类当成一种自定义的类型 5 类定义的变 ...
- winfrom---Window 消息大全
最近正在捣腾winfrom,遇到了关于window消息这一块的东西,正好在网上看到“微wx笑”的总结. 原文地址:http://blog.csdn.net/testcs_dn/article/deta ...
- elementUI使用实录
新项目开发用到了elementUI,但是对这个虽然会用,但是细枝末节的东西每次都需要看官方文档才能想起来怎么用,故,记之. 1.form表单 -- 表单验证 在防止用户犯错的前提下,尽可能让用户更早地 ...
- electron api sendInputEvent 源码
electron-master\electron-master\shell\browser\api\atom_api_web_contents.cc // Copyright (c) 2014 Git ...
- 工控安全入门之 Ethernet/IP
工控安全入门之 Ethernet/IP Ethernet/IP 与 Modbus 相比,EtherNet/IP 是一个更现代化的标准协议.由工作组 ControlNet International 与 ...