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 ...
随机推荐
- Django框架之第二篇--app注册、静态文件配置、form表单提交、pycharm连接数据库、django使用mysql数据库、表字段的增删改查、表数据的增删改查
本节知识点大致为:静态文件配置.form表单提交数据后端如何获取.request方法.pycharm连接数据库,django使用mysql数据库.表字段的增删改查.表数据的增删改查 一.创建app,创 ...
- python 字符串替换功能 string.replace()可以用正则表达式,更优雅
说起来不怕人笑话,我今天才发现,python 中的字符串替换操作,也就是 string.replace() 是可以用正则表达式的. 之前,我的代码写法如下,粗笨: 自从发现了正则表达式也生效后,代码变 ...
- Macvlan 和 IPvlan
介绍 macvlan 本身是 linxu kernel 模块,其功能是允许在同一个物理网卡上配置多个 MAC 地址,即多个 interface,每个 interface 可以配置自己的 IP.macv ...
- 测度(Measure)
测度概述 数学上,测度(Measure)是一个函数,它对一个给定集合的某些子集指定一个数,这个数可以比作大小.体积.概率等等.传统的积分是在区间上进行的,后来人们希望把积分推广到任意的集合上,就发展出 ...
- Bean named 'XXX' is expected to be of type [XXX] but was actually of type [com.sun.proxy.$Proxy7
AOP原理 <aop:aspectj-autoproxy />声明自动为spring容器中那些配置@aspectJ切面的bean创建代理,织入切面. <aop:aspectj-aut ...
- MySQLNonTransientConnectionException: Could not create connection to database server.
MySQLNonTransientConnectionException: Could not create connection to database server. Spring整合mybati ...
- exchange From Middle English eschaunge
exchange From Middle English eschaunge, borrowed from Anglo-Norman eschaunge exchange 1.An act of ex ...
- python关于try except的使用方法
一.常见错误总结 AttributeError 试图访问一个对象没有的树形,比如foo.x,但是foo没有属性x IOError 输入/输出异常;基本上是无法打开文件 ImportError 无法引入 ...
- linux技能四 用户管理
用户管理:用户类型,添加用户,修改用户,删除用户,查看用户信息,用户的切换,添加组,修改组,删除组,查看组 用户类型:超级用户:root,UID=1 系统用户:运行系统服务的,不能登陆的,UID=(1 ...
- Linux--基本目录
特点 系统版本:CentOS 6.5 Linux目录:一切从根开始 Linux下面的设备(磁盘)不挂载的话没有办法使用,使用设备必须有一个入口,挂载点实质就是一个目录. 目录结构及含义 目录 说明 b ...