题集链接

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. CDN绕过

    信息收集_CDN绕过 什么是CDN?为什么要绕过? ​ CDN全称是内容分发网络(content delivery network).其目的是让用户能够更快速的得到请求的数据. ​ 网上找了一张图片, ...

  2. python实现基于smtp发送邮件

    [前言] 在某些项目中,我们需要实现发送邮件的功能,比如: 爬虫结束后,发送邮件通知 定时发送邮件提醒待办事项 某项业务逻辑触发邮件通知 今天我们就分享如何基于smtp借助163邮箱来发送邮件 [实现 ...

  3. [题解] 序列(sequence)

    题目大意 给定一个长度为 \(N\)​ 的非负整数序列 \(A_1,A_2, \ldots ,A_N\)​,和一个正整数 \(M\)​.序列 \(A\) ​满足 \(\forall 1 \le i \ ...

  4. FinOps for Kubernetes - 如何拆分 Kubernetes 成本

    本文独立博客阅读地址:https://thiscute.world/posts/finops-for-kubernetes/ 目录 云计算成本管控 Kubernetes 成本分析的难点 Kuberne ...

  5. crontab和cron表达式详解

    引言 我们在定时任务中经常能接触到cron表达式,但是在写cron表达式的时候我们会遇到各种各样版本的cron表达式,比如我遇到过5位.6位甚至7位的cron表达式,导致我一度搞混这些表达式.更严重的 ...

  6. 4┃音视频直播系统之浏览器中通过 WebRTC 进行桌面共享

    一.共享桌面原理 共享桌面在直播系统中是一个必备功能 共享者:每秒钟抓取多次屏幕,每次抓取的屏幕都与上一次抓取的屏幕做比较,取它们的差值,然后对差值进行压缩:如果是第一次抓屏或切幕的情况,即本次抓取的 ...

  7. [ Module ] 环境变量管理工具 Module 安装和使用

    https://www.cnblogs.com/yeungchie/ 1. 工具下载 手动下载 modules-5.1.0 点击下载 wget 下载 wget https://jaist.dl.sou ...

  8. 前后端分离,SpringBoot如何实现验证码操作

    验证码的功能是防止非法用户恶意去访问登录接口而设置的一个功能,今天我们就来看看在前后端分离的项目中,SpringBoot是如何提供服务的. SpringBoot版本 本文基于的Spring Boot的 ...

  9. install dns server on ubuntu

    参考 CSDN/Ubuntu环境下安装和配置DNS服务器 在 Ubuntu 上安裝 DNS server Install BIND 9 on Ubuntu and Configure It for U ...

  10. 使用 Postman 实现 API 自动化测试

    背景介绍 相信大部分开发人员和测试人员对 postman 都十分熟悉,对于开发人员和测试人员而言,使用 postman 来编写和保存测试用例会是一种比较方便和熟悉的方式.但 postman 本身是一个 ...