题解 CF1082A 【Vasya and Book】

史上最难A题,没有之一

从题意可以看出,翻到目标页只有三种办法

  • 先从\(x\)到\(1\),再从\(1\)到\(y\)

  • 先从\(x\)到\(n\),再从\(n\)到\(y\)

  • 直接从\(x\)到\(y\)

三种的必要条件分别是

  • \((y-1)\mod d \equiv 0\)

  • \((n-y)\mod d \equiv 0\)

  • \(|x-y|\mod d \equiv 0\)

所以如果上面三种都不满足的话就输出\(-1\)

不然就取最小的输出

# include <bits/stdc++.h>

int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, x, y, d;
scanf("%d%d%d%d", &n, &x, &y, &d);
int ans = 0x7f7f7f7f;
if(abs(x - y) % d == 0)
ans = abs(x - y) / d;
if((y - 1) % d == 0)
ans = std::min(ans, (x - 1) / d + bool((x - 1) % d) + (y - 1) / d);
if ((n - y) % d == 0)
ans = std::min(ans, (n - x) / d + bool((n - x) % d) + (n - y) / d);
if(ans == 0x7f7f7f7f)
{
printf("-1\n");
continue;
}
printf("%d\n", ans);
}
return 0;
}

题解 CF1082B 【Vova and Trophies】

\(B\)比\(A\)水qwq

这题,对每一个''\(G\)'',求它这一块的左边界和右边界

然后对于每一个''\(S\)'',求一下他左边那块的大小,右边那块的大小,再判断一下他能不能把两块连在一起,不能就取大的那块,做完了

#include <bits/stdc++.h>

using std::string;

const int MaxN = 100010;

int a[MaxN];
int l[MaxN], r[MaxN]; int main()
{
int n;
string s;
scanf("%d", &n);
std::cin >> s;
int len = s.length();
int sum = 0, ans = 0;
for (int i = 0; i < len; i++)
a[i + 1] = s[i] == 'S' ? 0 : 1, sum += a[i + 1];
if (sum == 0)
return printf("0") * 0;
if (sum == n)
return printf("%d\n", n) * 0;
for (int i = 1; i <= n; i++)
{
if (a[i] == 1 && a[i - 1] == 1)
l[i] = l[i - 1];
else
l[i] = i;
}
for (int i = n; i >= 1; i--)
{
if (a[i] == 1 && a[i + 1] == 1)
r[i] = r[i + 1];
else
r[i] = i;
}
for (int i = 1; i <= n; i++)
{
if (a[i] == 0)
{
int tmp = 0;
if (a[i - 1])
tmp += r[i - 1] - l[i - 1] + 1;
if (a[i + 1])
tmp += r[i + 1] - l[i + 1] + 1;
if(tmp == sum)
ans = std::max(ans, tmp);
if (tmp < sum)
ans = std::max(ans, tmp + 1);
if (a[i - 1] && r[i - 1] - l[i - 1] + 1 < sum)
ans = std::max(r[i - 1] - l[i - 1] + 2, ans);
if (a[i + 1] && r[i + 1] - l[i + 1] + 1 < sum)
ans = std::max(r[i + 1] - l[i + 1] + 2, ans); }
}
printf("%d\n", ans);
return 0;
}

题解 CF1082C 【Multi-Subject Competition】

这个\(C\)好难啊

这是道前缀和好题

首先,读入后,把每一个分数扔进相应学科的桶

然后贪心地对每个桶排序

然后对于每一个桶,求前缀和,如果大于\(0\),就加到对应的\(ans[i]\)中(\(ans[i]\)记录的是每个学科\(i\)个人的最大得分)

最后输出

\[\max_{1<=i<=n}{ans[i]}
\]

#include <bits/stdc++.h>

# define int long long

using std::vector;
const int MaxN = 100010; int ans;
int sum[MaxN];
vector<int> v[MaxN];
int s[MaxN], rank[MaxN]; int cmp(int a, int b) { return a > b; } signed main()
{
int n, m, maxn = 0;
scanf("%I64d%I64d", &n, &m);
for (int i = 1; i <= n; i++)
{
scanf("%I64d%I64d", &s[i], &rank[i]);
v[s[i]].push_back(rank[i]);
maxn = std::max(rank[i], maxn);
}
if (maxn == 0)
return 0 * printf("0\n");
for (int i = 1; i <= m; i++)
{
if (v[i].size())
std::sort(v[i].begin(), v[i].end(), cmp);//排序
}
for(int i = 1; i <= m; i++)
{
int tmp = 0;
for(int j = 0; j < v[i].size(); j++)
{
tmp += v[i][j];
if(tmp <= 0)
break;
sum[j + 1] += tmp;//前缀和
}
}
printf("%d", *std::max_element(sum + 1, sum + n + 1));
return 0;
}

Educational Codeforces Round 55 题解的更多相关文章

  1. Educational Codeforces Round 55 (Rated for Div. 2) C. Multi-Subject Competition 【vector 预处理优化】

    传送门:http://codeforces.com/contest/1082/problem/C C. Multi-Subject Competition time limit per test 2 ...

  2. Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency

    E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...

  3. Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph

    D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...

  4. Educational Codeforces Round 55 (Rated for Div. 2):C. Multi-Subject Competition

    C. Multi-Subject Competition 题目链接:https://codeforces.com/contest/1082/problem/C 题意: 给出n个信息,每个信息包含专业编 ...

  5. Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies

    传送门 https://www.cnblogs.com/violet-acmer/p/10035971.html 题意: Vova有n个奖杯,这n个奖杯全部是金奖或银奖,Vova将所有奖杯排成一排,你 ...

  6. Educational Codeforces Round 55 (Rated for Div. 2) A - Vasya and Book

    传送门 https://www.cnblogs.com/violet-acmer/p/10035971.html 题意: 一本书有n页,每次只能翻 d 页,问从x页到y页需要翻动几次? 注意:往前翻最 ...

  7. Educational Codeforces Round 19 题解【ABCDE】

    A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...

  8. Educational Codeforces Round 55 (Rated for Div. 2) A/B/C/D

    http://codeforces.com/contest/1082/problem/A WA数发,因为默认为x<y = = 分情况讨论,直达 or x->1->y  or  x-& ...

  9. [Educational Codeforces Round 55 (Rated for Div. 2)][C. Multi-Subject Competition]

    https://codeforc.es/contest/1082/problem/C 题目大意:有m个类型,n个人,每个人有一个所属类型k和一个能力v,要求所选的类型的人个数相等并且使v总和最大(n, ...

随机推荐

  1. CH01-ZYNQ修炼秘籍-LINUX篇-虚拟机环境搭建

    CH01基于Ubuntu系统的ZYNQ-7000开发环境的搭建 1.1概述 实验环境: Windows 10 专业版 Vmware workstation 14.1.1 Ubuntu 16.04.3 ...

  2. Linux权限管理:ACL 权限

    1.ACL 是什么 ACL的全称是 Access Control List (访问控制列表) ,一个针对文件/目录的访问控制列表.它在UGO权限管理的基础上为文件系统提供一个额外的.更灵活的权限管理机 ...

  3. Ubuntu install android studio

    Ubuntu install android studio 1. 安装 openjdk8,并在配置文件 /etc/profile 中,追加如下内容: sudo aptitude install ope ...

  4. mybatis - 问题记录

    记录使用 mybatis 过程中遇到的一些报错,及原因以及解决方法. 1. 报错: Could not find parameter map com.lx.mapper.HotelMapper.map ...

  5. MP4数据封装格式

    一 .MP4   https://blog.csdn.net/sdsszk/article/details/90719075 MP4   由很多个ATOM 嵌套构成,主要的ATOM包括  [ftyp] ...

  6. 只需五分钟-用Maven快速搭建Spring Cloud微服务

    Maven安装手册 1.准备安装包 安装包: apache-maven-3.5.4-bin.zip  (最好JDK 1.7及以上版本) 集成包: eclipse-maven3-plugin.zip 2 ...

  7. Python中的上下文管理器(contextlib模块)

    上下文管理器的任务是:代码块执行前准备,代码块执行后收拾 1 如何使用上下文管理器: 打开一个文件,并写入"hello world" filename="my.txt&q ...

  8. sed初级教程

    简介 sed是作为特殊目的的编辑器而创建的,用于专门执行脚本:与ed不同,它不能交互地使用.sed面向字符流.默认情况下,到sed的所有输入都会经过相应的处理,并转为标 准输出.输入文件本身不发生改变 ...

  9. IPC——概述

    现代操作系统下的内存 现在的OS都引入了虚拟内存机制.我们说的内存空间,实际上虚拟内存空间,CPU执行PC指向的命令,PC指向的就是虚拟内存空间地址.虚拟内存机制只不过是OS为我们做了一层虚拟内存地址 ...

  10. Go语言中Goroutine的设置

    一. 通过runtime包进行多核设置 1.NumCPU()获取当前系统的cpu核数 2.GOMAXPROCS设置当前程序运行时占用的cpu核数 版本1.6之前默认是使用1个核,而之后是全部使用. 好 ...