题解 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. Fiddler讲解2

    想要 浏览更多Fiddler内容:请点击进入Fiddler官方文档 阅读目录: 一.查看网络流量: 二.检查网络流量: 三.查看Web会话摘要: 四.查看Web会话统计信息: 五.查看Web会话内容: ...

  2. Jira是什么

    JIRA这个工具接触有好几年了,在多个海外项目上都用过这个工具.去年又在项目上深度使用后就有点爱不释手了,回国后也在找机会推荐给其它项目上用.最近正好有新项目需要用,借这个机会把JIRA的配置学习的过 ...

  3. 安装CentOS7服务器

    1. 基本安装 https://www.cnblogs.com/kreo/p/4396825.html 2.安装补充 防火墙 / FTP / Nginx https://www.cnblogs.com ...

  4. LeetCode每日一练(1-3)

    题目导航 1. 两数之和 2. 两数相加 3. 无重复字符的最长子串 1. 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的 ...

  5. 使用VS2012编译和使用C++ STL(STLport)

    使用VS2012编译和使用C++ STL(STLport) http://cstriker1407.info/blog/use-vs2012-to-compile-and-use-the-c-stl- ...

  6. JQuery里input属性赋值,取值prop()和attr()方法?

    一.赋值的时候 如果是<input type="checkbox" checked>这样的只有属性名就能生效的属性 推荐prop,即:$('input').prop(' ...

  7. 如何避免Linux操作系统客户端登陆超时-linux命令之TMOUT=

    工作中经常遇到使用ssh,telnet工具登陆Linux操作系统时,出现的超时问题,怎么处理呢? 添加下面命令: TMOUNT=

  8. Integer和int踩过的坑

    在做SSM项目时发现一个有趣的bug,在这里记录一下. 数据库表如下: 实体类:grade字段初始设定为int类型 在用mybatis对第三条数据进行修改时,希望赋值的更改,未赋值的不更改,测试运行 ...

  9. 对于Linux中文件描述符的疑问以及解决

    问题 ​ 每次web服务器或者是几乎所有Linux服务器都需要对文件描述符进行调整,我使用ulimit -n来查看当前用户的最多能打开的文件,默认设置的是1024个,但是系统运行起来以及开启一些简单的 ...

  10. JDK环境变量配置linux

    安装前先查看是否安装过jdk如果安装过则 卸载 1. 确定JDK的版本: rpm -qa | grep jdk rpm -qa | grep gcj 可能的结果是: libgcj-4.1.2-42.e ...