AtCoder Beginner Contest 127 解题报告
非常遗憾。当天晚上错过这一场。不过感觉也会掉分的吧。后面两题偏结论题,打了的话应该想不出来。
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} int main() {
int a = read(), b = read();
if (a >= ) b = b;
else if (a > ) b /= ;
else b = ;
cout << b << '\n';
return ;
}
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} int main() {
int r = read(), d = read(), x = read();
for (int i = ; i < ; i++) {
x = r * x - d;
printf("%d\n", x);
}
return ;
}
题意:有$N$张ID卡,编号为1到$N$,$M$扇门,每扇门对应着一个区间$\left[ L,R\right]$,在闭区间内的ID卡才能打开门,问有多少张ID卡能打开所有门。
思路:相当于$M$个区间求交集。然后就是求$L$的最大值和$R$的最小值,$L$大于$R$就无解,否则就是$R - L + 1$
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} int main() {
int n = read(), m = read();
int l = , r = n;
while (m--) {
int u = read(), v = read();
l = max(l, u); r = min(r, v);
}
int ans;
if (l > r) ans = ;
else ans = r - l + ;
printf("%d\n", ans);
return ;
}
题意:给$N$张卡片,有$M$次操作,每次可以至多把$B$张卡片上的数改成$C$,问最后$N$个数的和最大是多少。
思路:可以证(举例)明(发现),最后结果与操作顺序无关。
那么就把$N$个数放进小根堆,然后把操作按$C$ 的大小排,每次从最小的开始替换,如果最小的值比当前的$C$大就可以不用换了。这样保证了每个数最多进出队一次。
时间复杂度$O\left( n\log \left( n\right) \right)$(对吗?)
#include <bits/stdc++.h>
#define ll long long
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} const int M = 1e5 + ; struct P {
int b;ll c;
bool operator < (const P &rhs) const {
return c > rhs.c;
}
} p[M]; int main() {
int n = read(), m = read();
priority_queue<ll, vector<ll>, greater<ll> > que;
for (int i = ; i < n; i++) {
int x = read();
que.push((ll)x);
}
for (int i = ; i < m; i++) p[i].b = read(), p[i].c = (ll)read();
sort(p, p + m);
for (int i = ; i < m; i++) {
int b = p[i].b;
if (p[i].c <= que.top()) break;
while (b--) {
if (que.top() < p[i].c) {
que.pop();
que.push(p[i].c);
} else {
break;
}
}
}
ll sum = ;
while (!que.empty()) {
int x = que.top(); que.pop();
sum += x;
}
cout << sum << '\n';
return ;
}
题意:求一个网格图里面任取$K$点的曼哈顿距离之和
思路:$N\times M$的网格图里面任意两点的曼哈顿距离的平均值是$\dfrac {N+M}{3}$
答案就是$C^{k}_{N\times M}C^{2}_{k}\dfrac {N+M}{3}$
#include <bits/stdc++.h>
#define ll long long
using namespace std; const ll MOD = 1e9 + ; inline ll read() {
ll x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} ll qp(ll a, ll b) {
ll ans = ;
while (b) {
if (b & ) ans = ans * a % MOD;
a = a * a % MOD;
b >>= ;
}
return ans;
} const int N = 2e5 + ;
ll fac[N]; ll C(ll a, ll b) {
ll ans = fac[a] * qp(fac[b], MOD - ) % MOD;
ans = ans * qp((fac[a-b] + MOD) % MOD, MOD - ) % MOD;
return ans;
} int main() {
fac[] = ;
for (int i = ; i < N; i++) fac[i] = fac[i - ] * i % MOD;
ll n = read(), m = read(), k = read();
ll ans = C(n * m, k) * C(k, ) % MOD * qp(, MOD - ) % MOD;
ans = ans * (n + m) % MOD;
ans %= MOD;
cout << ans << '\n';
return ;
}
题意:有函数$f\left( x\right)$初始为0,两个操作,1是给$f\left( x\right)$加上$\left| x-a\right| +b$,2是询问函数的最小值及$x$
思路:可以证(举例)明(发现),函数的最小值一定$a$序列的中位数取到。
两个优先队列,一个降序一个升序,每次加入$a$都加入两个队列里,在比较他们的顶,降序的顶必须小于等于升序的顶,这样就能实现两个堆分别存储了序列的左半部分和右半部分。
同时,降序的顶就是取到的$x$
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} int main() {
int q = read();
priority_queue<int> l;
priority_queue<int, vector<int>, greater<int> > r;
long long ans = ;
while (q--) {
int t = read();
if (t == ) {
int a = read(), b = read();
ans += b;
l.push(a);
r.push(a);
if (l.top() > r.top()) {
int x = l.top(); l.pop();
int y = r.top(); r.pop();
ans += abs(x - y);
l.push(y); r.push(x);
}
} else {
printf("%d %lld\n", l.top(), ans);
}
}
return ;
}
AtCoder Beginner Contest 127 解题报告的更多相关文章
- AtCoder Beginner Contest 122 解题报告
手速选手成功混进rated only里面的前30名,但是总排名就到110+了... A - Double Helix #include <bits/stdc++.h> #define ll ...
- AtCoder Beginner Contest 146解题报告
题目地址 https://atcoder.jp/contests/abc146/tasks 感觉没有什么有意思的题... 题解 A #include <bits/stdc++.h> usi ...
- Atcoder Beginner Contest 124 解题报告
心态爆炸.本来能全做出来的.但是由于双开了Comet oj一个比赛,写了ABC就去搞那个的B题 还被搞死了. 回来写了一会D就过了.可惜比赛已经结束了.真的是作死. A - Buttons #incl ...
- AtCoder Beginner Contest 118 解题报告
A - B +/- A #include <bits/stdc++.h> int main() { int a, b; std::cin >> a >> b; b ...
- AtCoder Beginner Contest 120 解题报告
为啥最近都没有arc啊... A - Favorite Sound #include <algorithm> #include <iostream> #include < ...
- AtCoder Beginner Contest 117 解题报告
果然abc都是手速场. 倒序开的qwq. D题因为忘记1e12二进制几位上界爆了一发. A - Entrance Examination 就是除一下就行了... 看样例猜题意系列. #include& ...
- AtCoder Beginner Contest 132 解题报告
前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...
- AtCoder Beginner Contest 129 解题报告
传送门 写了四个题就跑去打球了.第五题应该能肝出来的. A - Airplane #include <bits/stdc++.h> using namespace std; inline ...
- AtCoder Beginner Contest 126 解题报告
突然6道题.有点慌.比赛写了五个.罚时爆炸.最后一个时间不太够+没敢写就放弃了. 两道题奇奇怪怪的WJ和20/20.今天的评测机是怎么了. A Changing a Character #includ ...
随机推荐
- 17 SpringMVC response响应
1.Model.ModelMap和ModelAndView的使用详解 Spring-MVC在请求处理方法可出现和返回的参数类型中,最重要就是Model和ModelAndView了,对于MVC框架,控制 ...
- Eclipse项目上传和下载到码云上
本文将介绍如何将本地的项目提交到开源中国的码云(版本控制器)上.改教程讲解过程比较详细,跟着做实现起来很简单.由于自己本身也是一个新手,所以不做过多的解释,只是单纯的描述了该如何去做,大家一起学习共同 ...
- [转帖]Exadata X8发布
Exadata X8发布 2019-04-09 10:45:32 dingdingfish 阅读数 193 文章标签: ExadataOracleX8 更多 分类专栏: Exadata 版权声明: ...
- Elasticsearch进阶篇(一)~head插件的安装与配置
1.安装node.js 1.1.通过官网下载二进制安装包 https://nodejs.org/en/download/ 选择对应的版本,右键复制下载链接,进入linux目录,切换到要安装目录的磁盘. ...
- Python-MySQL学习
内容来源(有删改):https://blog.csdn.net/hzw6991/article/details/87893761 上面链接同步视频地址:https://www.bilibili.com ...
- 认证授权-学习笔记2-OpenId Connect
简介 简单来说:OIDC是OpenID Connect的简称,OIDC=(Identity, Authentication) + OAuth 2.0.它在OAuth2上构建了一个身份层,是一个基于OA ...
- python 字符串替换功能 string.replace()可以用正则表达式,更优雅
说起来不怕人笑话,我今天才发现,python 中的字符串替换操作,也就是 string.replace() 是可以用正则表达式的. 之前,我的代码写法如下,粗笨: 自从发现了正则表达式也生效后,代码变 ...
- spring加载多个配置文件如何配置
为应用指定多个配置文件: 多个配置文件的关系: 并列 包含 并列关系 即有多个配置文件,需要同时加载这多个配置文件: 可以使用可变参数,数组和统配符进行加载: 可变参数 String config1 ...
- 2019 拼多多java面试笔试题 (含面试题解析)
本人3年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.拼多多等公司offer,岗位是Java后端开发,最终选择去了拼多多. 面试了很多家公司,感觉大部分公司考察的点都差 ...
- Java 之 Jedis
一.客户端 Jedis 1.Jedis Jedis 是一款java操作 redis 数据库的工具. 2.使用步骤 (1)下载 Jedis 的 jar 包 (2)使用: //1. 获取连接 Jedis ...