传送门

非常遗憾。当天晚上错过这一场。不过感觉也会掉分的吧。后面两题偏结论题,打了的话应该想不出来。

A - Ferris Wheel

#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 ;
}

B - Algae

#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 ;
}

C - Prison

题意:有$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 ;
}

D - Integer Cards

题意:给$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 ;
}

E - Cell Distance

题意:求一个网格图里面任取$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 - Absolute Minima

题意:有函数$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 解题报告的更多相关文章

  1. AtCoder Beginner Contest 122 解题报告

    手速选手成功混进rated only里面的前30名,但是总排名就到110+了... A - Double Helix #include <bits/stdc++.h> #define ll ...

  2. AtCoder Beginner Contest 146解题报告

    题目地址 https://atcoder.jp/contests/abc146/tasks 感觉没有什么有意思的题... 题解 A #include <bits/stdc++.h> usi ...

  3. Atcoder Beginner Contest 124 解题报告

    心态爆炸.本来能全做出来的.但是由于双开了Comet oj一个比赛,写了ABC就去搞那个的B题 还被搞死了. 回来写了一会D就过了.可惜比赛已经结束了.真的是作死. A - Buttons #incl ...

  4. AtCoder Beginner Contest 118 解题报告

    A - B +/- A #include <bits/stdc++.h> int main() { int a, b; std::cin >> a >> b; b ...

  5. AtCoder Beginner Contest 120 解题报告

    为啥最近都没有arc啊... A - Favorite Sound #include <algorithm> #include <iostream> #include < ...

  6. AtCoder Beginner Contest 117 解题报告

    果然abc都是手速场. 倒序开的qwq. D题因为忘记1e12二进制几位上界爆了一发. A - Entrance Examination 就是除一下就行了... 看样例猜题意系列. #include& ...

  7. AtCoder Beginner Contest 132 解题报告

    前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...

  8. AtCoder Beginner Contest 129 解题报告

    传送门 写了四个题就跑去打球了.第五题应该能肝出来的. A - Airplane #include <bits/stdc++.h> using namespace std; inline ...

  9. AtCoder Beginner Contest 126 解题报告

    突然6道题.有点慌.比赛写了五个.罚时爆炸.最后一个时间不太够+没敢写就放弃了. 两道题奇奇怪怪的WJ和20/20.今天的评测机是怎么了. A Changing a Character #includ ...

随机推荐

  1. SQL Server 参数嗅探问题

    摘要 MSSQL Server参数嗅探既是一个涉及知识面非常广泛,又是一个比较难于解决的课题,即使对于数据库老手也是一个比较头痛的问题.这篇文章从参数嗅探是什么,如何产生,表象是什么,会带来哪些问题, ...

  2. grpc Unary模式下客户端创建insecure channel的主要流程

    (原创)C/C/1.25.0-dev grpc-c/8.0.0, 使用的例子是自带的例子GreeterClient grpc Unary模式下客户端创建insecure channel的主要流程 gr ...

  3. 关于使用KubeSphere中的docker配置Harbor仓库http访问docker login登陆报错的解决办法

    # 先进入harbor目录中,停止harbor docker-compose stop # 然后修改docker相关文件 # 第一种方式:修改/etc/docker/daemon.json { &qu ...

  4. mybatis逆向生成dao mapper和example.java文件

    mabatis插件 <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>myba ...

  5. java之mybatis之缓存

    1.mybatis自带缓存功能.分为一级缓存,二级缓存. 2.一级缓存为 session 缓存,在一个 session中 ,一个查询的 select 语句只会执行一次,根据  <select&g ...

  6. 换个语言学一下 Golang (9)——结构体和接口

    基本上到这里的时候,就是上了一个台阶了.Go的精华特点即将展开. 结构体定义 上面我们说过Go的指针和C的不同,结构体也是一样的.Go是一门删繁就简的语言,一切令人困惑的特性都必须去掉. 简单来讲,G ...

  7. iOS 12中获取WiFi的SSID

    开始搞智能家居,wifi获取不到了?? 小插曲 旧方法失效,19-12-15更新,ios13开始需要请求定位信息 SSID全称Service Set IDentifier, 即Wifi网络的公开名称. ...

  8. linux入门—安装linux系统(1)

    一,linux介绍 linux是一套免费使用和自由传播的类Unix操作系统,简单的说就是不要钱,你可以随便使用,也可以分享给其他人. (剩下的详细内容,个人认为百度百科的内容比我瞎讲强的多,网址:ht ...

  9. window.requestAnimationFrame()的使用,处理更流畅的动画效果

    https://blog.csdn.net/w2765006513/article/details/53843169 window.requestAnimationFrame()的使用 2016年12 ...

  10. .gitignore详解(附上eclipse的java项目的 .gitignore文件)

    今天讲讲Git中非常重要的一个文件――.gitignore. 首先要强调一点,这个文件的完整文件名就是“.gitignore”,注意最前面有个“.”.这样没有扩展名的文件在Windows下不太好创建, ...