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题题解的更多相关文章

  1. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  2. Codeforces Round #599 (Div. 2)的简单题题解

    难题不会啊…… 我感觉写这个的原因就是因为……无聊要给大家翻译题面 A. Maximum Square 简单题意: 有$n$条长为$a_i$,宽为1的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...

  3. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  4. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  5. Codeforces Round #310 (Div. 2)--A(简单题)

    http://codeforces.com/problemset/problem/556/A 题意:给一个01字符串,把所有相邻的0和1去掉,问还剩下几个0和1. 题解:统计所有的0有多少个,1有多少 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #316 (Div. 2) (ABC题)

    A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...

  9. Codeforces Round #590 (Div. 3)【D题:26棵树状数组维护字符出现次数】

    A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...

  10. Codeforces Round #590 (Div. 3)【D题:维护26棵树状数组【好题】】

    A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...

随机推荐

  1. cyclone3内部资源

    CycloneIII内部资源概述 目录 CycloneIII内部资源概述 Logic Elements and Logic Array Blocks(逻辑元件和逻辑阵列块) LE LAB LAB In ...

  2. SpringMvc集成开源流量监控、限流、熔断降级、负载保护组件Sentinel

    前言:作者查阅了Sentinel官网.51CTO.CSDN.码农家园.博客园等很多技术文章都没有很准确的springmvc集成Sentinel的示例,因此整理了本文,主要介绍SpringMvc集成Se ...

  3. 231106-jmeter随笔

    1. 获取接口的执行时间 String ctime = prev.getTime().toString();2. String转int int c = Integer.parseInt(ctime); ...

  4. 0x04.信息收集

    探针 被动:借助网上的一些接口查询或者网上已经获取到的,查看历史信息. 主动:使用工具,从本地流量出发,探测目标信息,会发送大量流量到对方服务器上. 谷歌语法 懒人语法:https://pentest ...

  5. JSX 代码是如何“摇身一变”成为 DOM 的?

    JSX 是一种语法,并不是 React 中的内容,时下接入 JSX 语法的框架越来越多,但与之缘分最深的仍然是 React.本节来讲一下 React 是如何摇身一变成为 DOM 的. 我们平时在写Re ...

  6. vue-test --------事件修饰符

    <template> <h3>事件修饰符</h3> <a @click="clickHandle" href="www.baid ...

  7. 【大语言模型基础】60行Numpy教你实现GPT-原理与代码详解

    写在前面 本文主要是对博客 https://jaykmody.com/blog/gpt-from-scratch/ 的精简整理,并加入了自己的理解. 中文翻译:https://jiqihumanr.g ...

  8. Python——第四章:内置函数(下)

    内置函数的使用方法: locals:函数会以字典的类型返回当前位置的所有局部变量 globals:函数会以字典的类型返回全部局部变量 zip: 可以把多个可迭代内容进行合并 sorted: 排序 fi ...

  9. Ubuntu 命令使用方法

    apt-get 用作于deb包 yum作用于tar包(也可以运作于rpm包) 首先用yum list wget检查一下你的虚拟机有没有安装wget,如果安装了下面图中会显示 @dvd ,我的没有安装所 ...

  10. 技本功|Hive优化之Spark执行引擎参数调优(二)

    Hive是大数据领域常用的组件之一,主要是大数据离线数仓的运算,关于Hive的性能调优在日常工作和面试中是经常涉及的的一个点,因此掌握一些Hive调优是必不可少的一项技能.影响Hive效率的主要有数据 ...