A. Vasya and Chocolate

模拟题。数据会爆\(int\),要开\(long\) \(long\)

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int main(){
int T; scanf("%d", &T);
while(T--){
LL s, a, b, c;
scanf("%lld%lld%lld%lld", &s, &a, &b, &c);
LL buy = s / c, free = buy / a * b;
printf("%lld\n", buy + free);
}
return 0;
}

B. Vasya and Isolated Vertices

考虑最小时,两两连边,答案为\(max(n - 2 * m, 0)\)

考虑最大时,除了\(m\)为\(1或0\)特判以外,每次尝试用最多的边拓展一个点为不孤立的,则可以放\(now - 1\)条边连向之前所有的边。

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
LL n, m;
int main(){
cin >> n >> m;
cout << max(n - 2 * m, 0ll) << " ";
if(m == 0) printf("%lld\n", n);
else if(m == 1) printf("%lld\n", n - 2);
else{
int now = 2;
while(m - now + 1 > 0 && now < n) m -= (now - 1), now++;
printf("%lld\n", n - now);
}
return 0;
}

C. Make It Equal

我太弱了,只想到了\(O(nlogn)\)的做法...就是用树状数组维护前缀和,就能用\(O(logn)\)的时间计算出代价,然后弄一个指针从大往小搜就可以了...

#include <cstdio>
#include <iostream>
#include <cmath>
#include <limits.h>
typedef long long LL;
using namespace std;
const int N = 200010;
int n, k, a[N], cnt[N], ans = 0, maxn = -1, minn = INT_MAX;
LL c[N];
void add(int x, LL k){
for(; x <= maxn; x += x & -x) c[x] += k;
}
LL ask(int x){
LL res = 0;
for(; x; x -= x & -x) res += c[x];
return res;
}
LL inline get(int x){
return ask(maxn) - ask(x - 1);
}
int main(){
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%d", a + i), cnt[a[i]]++, maxn = max(maxn, a[i]), minn = min(minn, a[i]);
for(int i = maxn; i >= 1; i--)
add(i, (LL)cnt[i] * i);
for(int i = maxn; i >= 1; i--)
cnt[i] += cnt[i + 1]; int i = maxn - 1;
while(i >= minn){
ans++;
while(i - 1 >= minn && get(i) - (LL)(i - 1) * cnt[i] <= k) i--;
add(i, (LL)i * (cnt[i + 1]) - get(i + 1));
i--;
}
printf("%d\n", ans);
return 0;
}

其实可以在指针从上往下跳的过程中处理后缀和,所以可以用\(O(n)\)的时间解决辣:

#include <cstdio>
#include <iostream>
#include <cmath>
#include <limits.h>
typedef long long LL;
using namespace std;
const int N = 200010;
int n, k, a[N], cnt[N], po[N], ans = 0, maxn = -1, minn = INT_MAX;
LL c[N];
int main(){
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%d", a + i), po[a[i]]++, cnt[a[i]]++, maxn = max(maxn, a[i]), minn = min(minn, a[i]);
for(int i = maxn; i >= 1; i--)
cnt[i] += cnt[i + 1]; int i = maxn - 1;
c[maxn] = (LL)maxn * po[maxn];
while(i >= minn){
ans++;
c[i] = c[i + 1] + (LL)i * po[i];
while(i - 1 >= minn && c[i] - (LL)(i - 1) * cnt[i] <= k)
i--, c[i] = c[i + 1] + (LL)i * po[i];;
c[i] += (LL)i * (cnt[i + 1]) - c[i + 1];
i--;
}
printf("%d\n", ans);
return 0;
}

D. Three Pieces

\(pair<int, int>\)自带比较函数,所以省了不少功夫。写了一个优先队列\(bfs\)就过惹...

一共会有$3 *N ^ 4 $个状态,每次状态扩展最多要扩展\(4 * N\)级别,其实还会少。

总共复杂度为\(O(12 * N ^ 5)\),不会\(TLE\)。

#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 15;
int n, a[N][N];
PII num[N * N];
//0: 车、1: 马: 2、象
int dx[3][8] = {
{1, -1, 0, 0},
{1, 1, -1, -1, -2, -2, 2, 2},
{1, 1, -1, -1},
};
int dy[3][8] = {
{0, 0, 1, -1},
{2, -2, 2, -2, 1, -1, 1, -1},
{1, -1, 1, -1},
};
int size[3] = {4, 8, 4};
int ne[3] = {N, 1, N};
PII step[N][N][N * N][3];
struct Node{
int x, y, k, m, t, c;
};
bool operator < (const Node &x, const Node &y){
return x.t == y.t ? x.c > y.c : x.t > y.t;
}
bool inline check(int x, int y){
return x >= 1 && x <= n && y >= 1 && y <= n;
}
PII bfs(){
priority_queue<Node> q;
for(int i = 0; i < 3; i++){
q.push((Node){ num[1].first, num[1].second, 1, i, 0, 0});
step[num[1].first][num[1].second][0][i] = make_pair(0, 0);
} while(!q.empty()){
Node u = q.top(); q.pop();
if(u.k >= n * n){
return make_pair(u.t, u.c);
}
for(int i = 0; i < size[u.m]; i++){
for(int j = 1; j <= ne[u.m]; j++){
int nx = u.x + dx[u.m][i] * j, ny = u.y + dy[u.m][i] * j;
int nm = u.m, nt = u.t + 1, nc = u.c;
int nk = (num[u.k + 1] == make_pair(nx, ny)) ? u.k + 1 : u.k;
PII now = make_pair(nt, nc);
if(!check(nx, ny)) break;
if(now < step[nx][ny][nk][nm]){
step[nx][ny][nk][nm] = now;
q.push((Node){nx, ny, nk, nm, nt, nc});
}
}
}
for(int i = 0; i < 3; i++){
if(i == u.m) continue;
int nx = u.x, ny = u.y;
int nm = i, nt = u.t + 1, nc = u.c + 1;
int nk = u.k;
PII now = make_pair(nt, nc);
if(!check(nx, ny)) break;
if(now < step[nx][ny][nk][nm]){
step[nx][ny][nk][nm] = now;
q.push((Node){nx, ny, nk, nm, nt, nc});
}
}
}
return make_pair(-1, -1);
}
int main(){
memset(step, 0x3f, sizeof step);
scanf("%d", &n);
ne[0] = ne[2] = n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
scanf("%d", &a[i][j]), num[a[i][j]] = make_pair(i, j);
PII res = bfs();
printf("%d %d\n", res.first, res.second);
return 0;
}

E. Side Transmutations

组合数问题,我肯定是不会的...

设\(A\)为字符集合的长度。

对于每一段 $ [b_{i - 1} + 1,b_i] $ $ (1 <= i <= m)$

设这一段的长度\(len = b[i] - (b[i - 1] + 1) + 1 = b[i] - b[i - 1]\)

它有$A ^ {len} $种不同的选择方案:

  1. 翻过去不同,那么对应过去就有\(A ^ {len} - 1\) 种方案(不包括翻过去相同那种),由于可能算上等价操作,他俩算一个,所以它的贡献为 \(\frac{A ^ {len} * (A ^ {len} - 1)}{2}\)
  2. 翻过去相同,每种方案对应过去式唯一的,所以为\(A ^ {len}\)。

这两种方案相加再\(*\)入\(ans\)中即可。

对于\([b_m + 1, n - b_m]\)这段,选不选都不会造成重复,对答案的贡献是:

\(A ^ {n - b_m - (b _m + 1) + 1} = A ^ {n - 2 * b_m }\)

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int MOD = 998244353;
const int N = 200010;
int n, m, A, b[N];
int power(int a, int b){
int res = 1;
while(b){
if(b & 1) res = (LL)res * a % MOD;
a = (LL)a * a % MOD;
b >>= 1;
}
return res;
}
int main(){
cin >> n >> m >> A;
for(int i = 1; i <= m; i++) scanf("%d", b + i);
LL ans = 1;
for(int i = 1; i <= m; i++){
LL now = power(A, b[i] - b[i - 1]);
ans = (ans * ((now + now * (now - 1) / 2) % MOD)) % MOD;
}
ans = (ans * power(A, (n - 2 * b[m]))) % MOD;
cout << ans;
return 0;
}

Codeforces Edu Round 52 A-E的更多相关文章

  1. Codeforces Beta Round #52 (Div. 2)

    Codeforces Beta Round #52 (Div. 2) http://codeforces.com/contest/56 A #include<bits/stdc++.h> ...

  2. [CodeForces]Educational Round 52

    幸好我没有打这场,我VP的时候在C题就卡死了,我果然还是太菜了. A Vasya and Chocolate 题意:一个巧克力\(c\)元,买\(a\)赠\(b\),一共有\(n\)元,问能买几个巧克 ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. CH Round #52 还教室[线段树 方差]

    还教室 CH Round #52 - Thinking Bear #1 (NOIP模拟赛) [引子]还记得 NOIP 2012 提高组 Day2 中的借教室吗?时光飞逝,光阴荏苒,两年过去了,曾经借教 ...

  5. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  6. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  7. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  8. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  9. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

随机推荐

  1. tcp 输入 简析 转载

    正常来说 TCP 收消息过程会涉及三个队列: Backlog Queue sk->sk_backlog Prequeue tp->ucopy.prequeue Receive Queue  ...

  2. 378. Kth Smallest Element in a Sorted Matrix(大顶堆、小顶堆)

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...

  3. 适用初学者的5种Python数据输入技术

    摘要:数据是数据科学家的基础,因此了解许多加载数据进行分析的方法至关重要.在这里,我们将介绍五种Python数据输入技术,并提供代码示例供您参考. 数据是数据科学家的基础,因此了解许多加载数据进行分析 ...

  4. 配置Ceph的IPV6集群

    前言 对于IPV6实在是非常的陌生,所以本篇开始会讲一下最基本的网络配置,首先让网络能通起来,最开始就是因为不熟悉IPV6,而直接使用了link local地址,造成了mon部署的时候进程无法绑定到I ...

  5. SpringBoot加载配置文件的几种方式

    首先回忆一下在没有使用SpringBoot之前也就是传统的spring项目中是如何读取配置文件,通过I/O流读取指定路径的配置文件,然后再去获取指定的配置信息. 传统项目读取配置方式 读取xml配置文 ...

  6. docker搭建渗透环境并进行渗透测试

    目录 docker简介 docker的安装 docker.centos7.windows10(博主宿主机系统)之间相互通信 -docker容器中下载weblogic12c(可以略过不看) docker ...

  7. C++之父接受采访:对 C++ 成功的关键和发展历程进行了回顾

    C++ 的起源可以追溯到 40 年前,但它仍然是当今使用最广泛的编程语言之一. 到 2020 年 9 月为止,C++ 是仅次于 C 语言.Java 和 Python,位于全球第四的编程语言.根据最新的 ...

  8. PDF文件处理助手 3.3.2版本更新

    本次更新内容如下: 1.修复部分PDF在"去水印"-"文字水印"-"模式3"下识别不到的问题. 2.修复部分情况下可能无法正确加载授权的问题 ...

  9. LeetCode 030 Substring with Concatenation of All Words

    题目要求:Substring with Concatenation of All Words You are given a string, S, and a list of words, L, th ...

  10. Alpha冲刺-第七次冲刺笔记

    Alpha冲刺-冲刺笔记 这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE2 这个作业要求在哪里 https://edu.cnblogs. ...