Codeforces Round #667 (Div. 3) A - D

Problem A - Yet Another Two Integers Problem

https://codeforces.com/contest/1409/problem/A

Codeforces Round #667 (Div. 3) A - D题题解 - 图1

Example

input

  1. 6
  2. 5 5
  3. 13 42
  4. 18 4
  5. 1337 420
  6. 123456789 1000000000
  7. 100500 9000

output

  1. 0
  2. 3
  3. 2
  4. 92
  5. 87654322
  6. 9150

题意:

给定两个数 Codeforces Round #667 (Div. 3) A - D题题解 - 图2,问题最少多少次(每次能加Codeforces Round #667 (Div. 3) A - D题题解 - 图3 能使 Codeforces Round #667 (Div. 3) A - D题题解 - 图4 变为 Codeforces Round #667 (Div. 3) A - D题题解 - 图5

思路:

水题,直接看代码更快点

  1. #include<bits/stdc++.h>
  2. #define ms(a,b) memset(a,b,sizeof a)
  3. using namespace std;
  4. typedef long long ll;
  5. const int N = 1e5 + 100;
  6. ll n, m, a[N], i, j;
  7. void solve() {
  8. cin >> n >> m;
  9. ll cnt = abs(n - m) / 10;
  10. if (abs(n - m) % 10 != 0)cnt++;
  11. cout << cnt << endl;
  12. }
  13. int main() {
  14. //freopen("in.txt", "r", stdin);
  15. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  16. int t; cin >> t;
  17. while (t--) solve();
  18. }

Problem B - Minimum Product

https://codeforces.com/contest/1409/problem/B

Codeforces Round #667 (Div. 3) A - D题题解 - 图6

Example

input

  1. 7
  2. 10 10 8 5 3
  3. 12 8 8 7 2
  4. 12343 43 4543 39 123212
  5. 1000000000 1000000000 1 1 1
  6. 1000000000 1000000000 1 1 1000000000
  7. 10 11 2 1 5
  8. 10 11 9 1 10

output

  1. 70
  2. 77
  3. 177177
  4. 999999999000000000
  5. 999999999
  6. 55
  7. 10

题意:

给定 Codeforces Round #667 (Div. 3) A - D题题解 - 图7 求,在 Codeforces Round #667 (Div. 3) A - D题题解 - 图8Codeforces Round #667 (Div. 3) A - D题题解 - 图9Codeforces Round #667 (Div. 3) A - D题题解 - 图10 使得 $ a * b$ 最小。

思路:

先求出 Codeforces Round #667 (Div. 3) A - D题题解 - 图11%2C%20max(b%20-%20n%2C%20y))#card=math&code=mins%20%3D%20min%28max%28a%20-%20n%2C%20x%29%2C%20max%28b%20-%20n%2C%20y%29%29) 。所以目标值一定是 Codeforces Round #667 (Div. 3) A - D题题解 - 图12%20-%20mins)#card=math&code=mins%20%2A%20%28max%28a%20%2B%20b%20-%20n%2C%20x%20%2B%20y%29%20-%20mins%29)。

  1. #include<bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. void solve() {
  5. ll a, b, x, y, n;
  6. cin >> a >> b >> x >> y >> n;
  7. ll mins = min(max(a - n, x), max(b - n, y));
  8. cout << mins * (max(a + b - n, x + y) - mins) << endl;
  9. }
  10. int main() {
  11. //freopen("in.txt", "r", stdin);
  12. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  13. int t; cin >> t;
  14. while (t--) solve();
  15. }

Problem C - Yet Another Array Restoration

https://codeforces.com/contest/1409/problem/C

Codeforces Round #667 (Div. 3) A - D题题解 - 图13

Example

input

  1. 5
  2. 2 1 49
  3. 5 20 50
  4. 6 20 50
  5. 5 3 8
  6. 9 13 22

output

  1. 1 49
  2. 20 40 30 50 10
  3. 26 32 20 38 44 50
  4. 8 23 18 13 3
  5. 1 10 13 4 19 22 25 16 7

就是从后往前预处理出来一个最大值就ok了,详情请看代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int t,n,x,y;
  4. int main()
  5. {
  6. ios::sync_with_stdio(false);
  7. cin.tie(0);cout.tie(0);
  8. cin>>t;
  9. while(t--)
  10. {
  11. cin>>n>>x>>y;
  12. int dist =y-x;//获取2点之间的距离
  13. int idx;
  14. for(idx=n-1;;idx--)//从后往前预处理最大值,如果等于n 就等于5个1是不行的
  15. //就是相当于把y到x的区间分成最长距离的多少份
  16. {
  17. if(dist%idx==0)break;
  18. }
  19. dist/=idx;//获取最大值
  20. for(int i=0;i<n-1&&y-dist>0;i++)//找到第一个元素
  21. {
  22. y-=dist;
  23. }
  24. for(int i=0;i<n;i++)
  25. {
  26. cout<<y<<' ';
  27. y+=dist;
  28. }
  29. cout<<endl;
  30. }
  31. return 0;
  32. }

Problem D - Decrease the Sum of Digits (思维问题+构造)

https://codeforces.com/contest/1409/problem/D

Codeforces Round #667 (Div. 3) A - D题题解 - 图14

Example

input

  1. 5
  2. 2 1
  3. 1 1
  4. 500 4
  5. 217871987498122 10
  6. 100000000000000001 1

output

  1. 8
  2. 0
  3. 500
  4. 2128012501878
  5. 899999999999999999

题意:

给定一个大数Codeforces Round #667 (Div. 3) A - D题题解 - 图15Codeforces Round #667 (Div. 3) A - D题题解 - 图16 ,求最小移动次数Codeforces Round #667 (Div. 3) A - D题题解 - 图17#card=math&code=%28n%20%3D%20n%20-%201%29) 以使Codeforces Round #667 (Div. 3) A - D题题解 - 图18 小于或等于 Codeforces Round #667 (Div. 3) A - D题题解 - 图19

理解完题意就很简单了。只需要去处理各位的情况的即可,关键语句在

  1. while (gsm(n) > s) {
  2. ll cur = n / cn; cur %= 10;
  3. ans += (10 - cur) * cn;
  4. n += (10 - cur) * cn;
  5. cn *= 10;
  6. }//仔细理解
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll gsm(ll n) {
  5. ll re = 0;
  6. while (n) {
  7. re += n % 10; n /= 10;
  8. }
  9. return re;
  10. }
  11. int main() {
  12. int t; cin >> t;
  13. while (t--) {
  14. ll n, s;
  15. cin >> n >> s;
  16. ll cn = 1, ans = 0;
  17. while (gsm(n) > s) {
  18. ll cur = n / cn; cur %= 10;
  19. ans += (10 - cur) * cn;
  20. n += (10 - cur) * cn;
  21. cn *= 10;
  22. }
  23. cout << ans << "\n";
  24. }
  25. }