Codeforces Round #667 (Div. 3) A - D题题解
Codeforces Round #667 (Div. 3) A - D
Problem A - Yet Another Two Integers Problem
https://codeforces.com/contest/1409/problem/A

Example
input
6
5 5
13 42
18 4
1337 420
123456789 1000000000
100500 9000
output
0
3
2
92
87654322
9150
题意:
给定两个数 \(a、b\),问题最少多少次(每次能加\(k ∈ [1:10]\) 能使 \(a\) 变为 \(b\)
思路:
水题,直接看代码更快点
#include<bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int N = 1e5 + 100;
ll n, m, a[N], i, j;
void solve() {
cin >> n >> m;
ll cnt = abs(n - m) / 10;
if (abs(n - m) % 10 != 0)cnt++;
cout << cnt << endl;
}
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) solve();
}
Problem B - Minimum Product
https://codeforces.com/contest/1409/problem/B

Example
input
7
10 10 8 5 3
12 8 8 7 2
12343 43 4543 39 123212
1000000000 1000000000 1 1 1
1000000000 1000000000 1 1 1000000000
10 11 2 1 5
10 11 9 1 10
output
70
77
177177
999999999000000000
999999999
55
10
题意:
给定 \(a、b、x、y、n\) 求,在 \(n\) 次 \(a - 1\) 或 \(b - 1\) 使得 $ a * b$ 最小。
思路:
先求出 \(mins = min(max(a - n, x), max(b - n, y))\) 。所以目标值一定是 \(mins * (max(a + b - n, x + y) - mins)\)。
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void solve() {
ll a, b, x, y, n;
cin >> a >> b >> x >> y >> n;
ll mins = min(max(a - n, x), max(b - n, y));
cout << mins * (max(a + b - n, x + y) - mins) << endl;
}
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) solve();
}
Problem C - Yet Another Array Restoration
https://codeforces.com/contest/1409/problem/C

Example
input
5
2 1 49
5 20 50
6 20 50
5 3 8
9 13 22
output
1 49
20 40 30 50 10
26 32 20 38 44 50
8 23 18 13 3
1 10 13 4 19 22 25 16 7
就是从后往前预处理出来一个最大值就ok了,详情请看代码
#include<bits/stdc++.h>
using namespace std;
int t,n,x,y;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>t;
while(t--)
{
cin>>n>>x>>y;
int dist =y-x;//获取2点之间的距离
int idx;
for(idx=n-1;;idx--)//从后往前预处理最大值,如果等于n 就等于5个1是不行的
//就是相当于把y到x的区间分成最长距离的多少份
{
if(dist%idx==0)break;
}
dist/=idx;//获取最大值
for(int i=0;i<n-1&&y-dist>0;i++)//找到第一个元素
{
y-=dist;
}
for(int i=0;i<n;i++)
{
cout<<y<<' ';
y+=dist;
}
cout<<endl;
}
return 0;
}
Problem D - Decrease the Sum of Digits (思维问题+构造)
https://codeforces.com/contest/1409/problem/D

Example
input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
output
8
0
500
2128012501878
899999999999999999
题意:
给定一个大数\(s\) 和 \(n\) ,求最小移动次数\((n = n - 1)\) 以使\(n\) 小于或等于 \(s\)。
理解完题意就很简单了。只需要去处理各位的情况的即可,关键语句在
while (gsm(n) > s) {
ll cur = n / cn; cur %= 10;
ans += (10 - cur) * cn;
n += (10 - cur) * cn;
cn *= 10;
}//仔细理解
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gsm(ll n) {
ll re = 0;
while (n) {
re += n % 10; n /= 10;
}
return re;
}
int main() {
int t; cin >> t;
while (t--) {
ll n, s;
cin >> n >> s;
ll cn = 1, ans = 0;
while (gsm(n) > s) {
ll cur = n / cn; cur %= 10;
ans += (10 - cur) * cn;
n += (10 - cur) * cn;
cn *= 10;
}
cout << ans << "\n";
}
}
Codeforces Round #667 (Div. 3) A - D题题解的更多相关文章
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces Round #599 (Div. 2)的简单题题解
难题不会啊…… 我感觉写这个的原因就是因为……无聊要给大家翻译题面 A. Maximum Square 简单题意: 有$n$条长为$a_i$,宽为1的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- BestCoder Round #11 (Div. 2) 前三题题解
题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...
- Codeforces Round #310 (Div. 2)--A(简单题)
http://codeforces.com/problemset/problem/556/A 题意:给一个01字符串,把所有相邻的0和1去掉,问还剩下几个0和1. 题解:统计所有的0有多少个,1有多少 ...
- Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #336 (Div. 2)-608A.水题 608B.前缀和
A题和B题... A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabyte ...
- Codeforces Round #316 (Div. 2) (ABC题)
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...
- Codeforces Round #590 (Div. 3)【D题:26棵树状数组维护字符出现次数】
A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...
- Codeforces Round #590 (Div. 3)【D题:维护26棵树状数组【好题】】
A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...
随机推荐
- python计算代码运行时间
记录一下自己用python编写计算运行时间的代码 时间类 import time import numpy as np # 编写时间类来方便操作 class Timer: def __init__(s ...
- phpmyadmin修改上传限制,phpmyadmin修改上传文件大小限制,docker版本phpmyadmin
我用的是DOCKER 版本的phpmyadmin 修改/usr/local/etc/php/conf.d/phpmyadmin-misc.ini 内的限制变量文件为 100M,重启docker 容器后 ...
- 重磅:谷歌发布最强大AI模型【Google Gemini】
一.前言 北京时间 2023年12 月 13 日Google 发布了最新的 Gemini Pro模型,并且提供了 API 访问. 一个更好的消息是:Gemini Pro 可免费使用.赶紧体验起来吧~ ...
- 【UniApp】-uni-app-自定义组件
前言 经过上个章节的介绍,大家可以了解到 uni-app-网络请求的基本使用方法 那本章节来给大家介绍一下 uni-app-自定义组件 的基本使用方法 原本打算是直接写项目的,在写项目之前还有个内容需 ...
- 华企盾DSC在苹果电脑上申请审批没有通知
由于系统通知这里没有允许DSC通知,开启后即可.系统偏好设置-通知与专注模式-通知
- WebView中的页面调试方法
在 iOS 12 中,苹果正式弃用 UIWebView,改成 WKWebView,参考官方声明. 后者在性能.稳定性.功能方面有很大提升,并且与 Safari 具有相同的 JavaScript 引擎( ...
- 从零玩转第三方登录之WeChat公众号扫码关注登陆 -wechatgzh
title: 从零玩转第三方登录之WeChat公众号扫码关注登陆 date: 2022-09-27 22:46:53.362 updated: 2023-03-30 13:28:41.359 url: ...
- kubernetes之部署nginx+vue前端(一)
kubernetes之部署nginx+vue前端(一) k8s系列项目的部署方式之一使用了kubernetes部署nginx+vue前端. 一.打包前端 将dist与Dockerfile放到同一目录下 ...
- 基于FPGA的电子琴设计(按键和蜂鸣器)---第一版---郝旭帅电子设计团队
本篇为各位朋友介绍基于FPGA的电子琴设计(按键和蜂鸣器)----第一版. 功能说明: 外部输入七个按键,分别对应音符的"1.2.3.4.5.6.7",唱作do.re.mi.fa. ...
- Windows中开启自动dump的方法
@echo off echo 正在启用Dump... reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error ...