题集链接

A Optimal Path

代码

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 1e6;
void solve()
{
int n, m;
cin >> n >> m;
ll ans = 0;
for (int i = 1; i <= m; i++)
ans += i;
for (int i = 2; i <= n; i++)
ans += (i - 1) * m + m;
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}

B Palindromic Numbers

题意

给一个 n 位数 a ,找一个 n 位数 b ,使得 a+b 为回文数.

思路

a 首位小于9,用 n 位 99...99 减去 a 得到 b.

a 首位等于9,用 n+1位 11...11 减去 a 得到 b.

注意要使用高精度减法.

代码

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 1e6;
string s;
void clake()
{
const int MAXN = 1e5 + 4;
char tmp[MAXN] = {};
int a[MAXN] = {};
int b[MAXN] = {};
int c[MAXN] = {};
string s1;
for (int i = 0; i <= s.size(); i++)
s1 += '1';
int lena = s1.size();
int lenb = s.size();
for (int i = 0; i < lena; i++)
a[i] = s1[lena - i - 1] - '0'; for (int i = 0; i < lenb; i++)
b[i] = s[lenb - i - 1] - '0'; for (int i = 0; i < lena; i++)
{
if (a[i] < b[i])
{
a[i + 1]--;
a[i] += 10;
}
c[i] = a[i] - b[i];
} for (int i = lena - 1; i >= 0; i--)
{ if (0 == c[i] && lena > 1)
{
lena--;
}
else
{ break;
}
} for (int i = lena - 1; i >= 0; i--)
cout << c[i];
}
void solve()
{
int n; cin >> n >> s;
if (s[0] != '9')
{
for (int i = 0; i < n; i++)
cout << 9 - (s[i] - '0');
}
else
clake();
cout << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}

D River Locks

题意

有连续地一系列水池,每个水池上面都有一个进水管,进水速率均为1升/秒,每个水池的容积为 vi , 进水时 ,水池满后会流向下一个水池,

进行q次询问,每次询问在 ti 时间内使得全部水池变满所开水管的数量的最小值

思路

首先对于一个水槽,其能被填满的最小时间(就假设前面都注水)为   ,其中  为前缀和。那么处理出   我们就知道无解的界。

然后因为你总要填满所有的水槽,即水的体积一定是 ,所以对于有解的情况答案一定为 

代码

#include <bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
// typedef long long ll;
const int N = 1e6;
int s[N], d[N], n;
void solve()
{
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int mas = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> s[i];
s[i] = s[i] + s[i - 1];
mas = max(mas, s[i] / i + (s[i] % i == 0 ? 0 : 1));
}
int q;
cin >> q;
while (q--)
{
int a;
cin >> a;
if (a < mas)
cout << "-1\n";
else
cout << s[n] / a + (s[n] % a == 0 ? 0 : 1) << endl;
} return 0;
}

C Helping the Nature

题意

给定一个长度为n的数组,定义如下操作

1.选择 i() ,使  到  的每一个数字都减一

2.选择 i  ()   ,使  到  的每一个数字都减一

3.使全部数字都加1

问使得全部数字变为0的最小操作数

思路

使得全部数都变为0等价于使差分数组全变为0,

用差分的操作来转换以上操作

1.b[1] -= 1,b[i + 1] += 1
2.b[i] -= 1
3.b[1] += 1

代码

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 1e3 + 233; void solve()
{
int n;
cin >> n;
ll s[n + 10] = {};
ll d[n + 10] = {};
for (int i = 1; i <= n; i++)
{
cin >> s[i];
d[i] = s[i] - s[i - 1];
}
ll ans = 0;
for (int i = 2; i <= n; i++)
{
if (d[i] < 0)
{
d[1] += d[i];
ans -= d[i];
}
else
{
ans += d[i];
}
}
cout << ans + abs(d[1]) << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}

Codeforces Round #802 (Div. 2)的更多相关文章

  1. Codeforces Round #802 (Div. 2)C. Helping the Nature(差分)

    题目链接 题目大意: 给你一个有n个元素的数组a,你可以通过一下三种操作使数组的每一个值都为0: 选择一个下标i,然后让a[1],a[2]....a[ i ] 都减一; 选择一个下标i,然后让a[i] ...

  2. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  8. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. Python实现双X轴双Y轴绘图

    诈尸人口回归.这一年忙着灌水忙到头都掉了,最近在女朋友的提醒下终于想起来博客的账号密码,正好今天灌水的时候需要画一个双X轴双Y轴的图,研究了两小时终于用Py实现了.找资料的过程中没有发现有系统的文章, ...

  2. Envoy熔断限流实践(二)Rainbond基于RLS服务全局限流

    Envoy 可以作为 Sevice Mesh 微服务框架中的代理实现方案,Rainbond 内置的微服务框架同样基于 Envoy 实现.本文所描述的全局限速实践也是基于 Envoy 已有的方案所实现. ...

  3. 数据库基础知识详解五:MySQL中的索引和其两种引擎、主从复制以及关系型/非关系型数据库

    1.MySQL中的索引 在MySQL,索引是由B+树实现的,B+是一种与B树十分类似的数据结构. 形如下面这种: 其结构特点: (1)有n课子树的结点中含有n个关键码. (2)非根节点子节点数: ce ...

  4. JS 加载

    DOM 加载完毕后执行,不需要等待image.js.css.iframe等加载 1.$(function() {}) 2.$(document).ready(function() {})  不要写成 ...

  5. nodejs + koa + typescript 集成和自动重启

    版本说明 Node.js: 16.13.1 全局安装 TypeScript yarn global add typescript 创建项目 创建如下目录结构 project ├── src │ └── ...

  6. 【Java8新特性】Lambda表达式

    一.Lambda 表达式 是什么? Lambda读音:拉姆达. Lambda是一个匿名函数,匿名函数就是一个没有名字的函数. Lambda 允许把函数作为一个方法的参数(函数作为参数传递进方法中). ...

  7. SpringBoot线程池

    1.遇到的场景 提高一下插入表的性能优化,两张表,先插旧的表,紧接着插新的表,若是一万多条数据就有点慢了 2.使用步骤 用Spring提供的对ThreadPoolExecutor封装的线程池Threa ...

  8. 1.还不会部署高可用的kubernetes集群?看我手把手教你使用二进制部署v1.23.6的K8S集群实践(上)

    公众号关注「WeiyiGeek」 设为「特别关注」,每天带你玩转网络安全运维.应用开发.物联网IOT学习! 本章目录: 0x00 前言简述 0x01 环境准备 主机规划 软件版本 网络规划 0x02 ...

  9. 『忘了再学』Shell基础 — 16、位置参数变量

    目录 1.位置参数变量$n 2.位置参数变量$*和$@ 3.位置参数变量$# 位置參数变量的作用主要用于脚本的传参. 位置參数变量的名称和作用都是确定不能改变的,但是该变量的内容是可以更改的,也就是变 ...

  10. SPPNet(特征金字塔池化)学习笔记

    SPPNet paper:Spatial pyramid pooling in deep convolutional networks for visual recognition code 首先介绍 ...