传送门

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

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. 24 AdminLTE 基础入门

    1.AdminLTE介绍 AdminLTE是一款建立在bootstrap和jquery之上的开源的模板主题工具,它提供了一系列响应的.可重复使用的组件,并内置了多个模板页面:同时自适应多种屏幕分辨率, ...

  2. SQL Server 中日志的的作用(Redo和Undo)

    简介 之前我已经写了一个关于SQL Server日志的简单系列文章.本篇文章会进一步挖掘日志背后的一些概念,原理以及作用. 数据库的可靠性 在关系数据库系统中,我们需要数据库可靠,所谓的可靠就是当遇见 ...

  3. 【LEETCODE】66、字符串分类,hard级别,题目:32,72,76

    package y2019.Algorithm.str.hard; import java.util.Stack; /** * @ProjectName: cutter-point * @Packag ...

  4. Go操作ini文件

    除了采用json,yaml等格式之外,常用的配置文件还有ini格式的. cfg, err := ini.Load(fyPath + "\\ServerSystem.ini") // ...

  5. LOJ2001 SDOI2017 树点涂色 LCT、线段树

    传送门 注意到每一次\(1\ x\)操作相当于一次LCT中的access操作.由LCT复杂度证明可以知道access的总次数不会超过\(O(nlogn)\),我们只需要模拟这个access的过程并在其 ...

  6. Deploy custom service on non hadoop node with Apache Ambari

    1   I want to deploy a custom service onto non hadoop nodes using Apache Ambari. I have created a cu ...

  7. 解决C#调用COM组件异常来自 HRESULT:0x80010105 (RPC_E_SERVERFAULT)的错误

    最近C#调用COM时,遇到了异常来自 HRESULT:0x80010105 (RPC_E_SERVERFAULT)的错误 后面找了一下,发现是在线程里调用COM组件引起的. C++调用COM时,会调用 ...

  8. Sqlserver 总结(2) 存储过程

    目录 写在前面 什么是存储过程 存储过程的优点 存储过程的分类 1.只返回单一记录集的存储过程 2.没有输入输出的存储过程 3.有返回值的存储过程 4.有输入参数和输出参数的存储过程 5.同时具有返回 ...

  9. C#基础—数组

    C#基础之数组 1.   数组的定义与初始化 一维数组: (1)            int [] A = new int[4]{ 0,1,2,3}; (2)            int[] B ...

  10. docker build 错误 /usr/share/dotnet/sdk/2.1.801/Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3245: Could not resolve this reference

    docker dotnet Restore 的时候报错, 一度怀疑是linux的dotnet core sdk没有装好, 卸了装, 装了卸, 试了好几遍还是无效(Microsoft.Common.Cu ...