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. Golang中如何自定义时间类型进行xml、json的序列化/反序列化

    在日常开发工作中,我们进行会遇到将 struct 序列化 json字符串以及将 json字符串 反序列化为 struct 的场景,大家也对此十分熟悉. 最近工作中,遇到了需要将 struct 序列化 ...

  2. vertx的学习总结6之动态代理类和测试

    Beyond the event bus 一.章节覆盖: 如何在事件总线之上公开服务 verticles和事件总线服务的异步测试 动态代理: MyService 接口 package porxy.te ...

  3. Redis 学习笔记2:持久化

    目录 1 什么是持久化 1.1 aof 1.2 rdb 2 RDB持久化 2.1 RDB 是什么 2.2 手动触发 3 AOF持久化 3.1 aof 是什么 3.2 appendfile 文件说明: ...

  4. CodeForces - 764C

    C. Timofey and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. 浅谈数字孪生和GIS融合的必要性

    随着科技的不断发展和应用的不断深入,数字孪生和GIS在各自领域中展现出巨大的潜力.然而,更引人注目的是,数字孪生和GIS的融合将为许多行业带来全新的机遇和变革.在本文中,我们将探讨数字孪生和GIS融合 ...

  6. pytest框架学习-标签@pytest.mark.

    标签 自定义标签(区分大小写) 可以标记测试用例,对测试用例进行分组,有利于对测试用例进行筛选. 比如:给用例打标为API,代表接口自动化的用例,打标方法为@pytest.mark.API,打标后,需 ...

  7. StringBuilder、StringBuffer

    StringBuilder 1.concat() 拼接字符串 2.indexOf() 查找 3.replace() 替换 4.subString(1,2) 截取 0,1,2 1开始 2结束 Strin ...

  8. 11 个步骤完美排查Linux服务器是否被入侵

    文章来源公众号:LemonSec 随着开源产品的越来越盛行,作为一个Linux运维工程师,能够清晰地鉴别异常机器是否已经被入侵了显得至关重要,个人结合自己的工作经历,整理了几种常见的机器被黑情况供参考 ...

  9. zabbix常用监控项

    https://blog.csdn.net/xkjcf/article/details/78559273?locationNum=10&fps=1 agent.ping  #agent是否在线 ...

  10. Programming abstractions in C阅读笔记:p184-p195

    <Programming Abstractions In C>学习第61天,p184-p195总结. 一.技术总结 1.mutual recursion 2.natural number ...