[CodeForces-1225A] Forgetting Things 【构造】
Tags: problem solution codeforces problem solution construction
Title Description
Time limit
2000 ms
Memory limit
524288 kB
Source
Technocup 2020 - Elimination Round 2
Tags
math *900
Site
https://codeforces.com/problemset/problem/1225/a
Face questions
Example
Input1
1 2
Output1
199 200
Input2
4 4
Output2
412 413
Input3
5 7
Output3
-1
Input4
6 2
Output4
-1
Subject to the effect
Given (d_a, d_b \) \ number as a (first from left) on the highest of the two numbers, I asked if he could find such a \ (A, b \) , so that \ (a + 1 = b \ ) . If the output is not -1.
For example,
given 12, we can easily find 199 + 1 = 200, then we output 199,200.
Given 62, we could not find \ (a, b \) to meet the requirements, then we output -1.
Resolve
Simple construction.
Method of constructing the answer should have a variety.
Points discuss,
if given two numbers are equal, then output \ (D_A \ Times 10 \; \; D_B \ Times + 10. 1 \) .
If a given \ (. 1 + D_A D_B = \) , then the direct output \ (d_a \; \; d_b \) can.
A special case, if a given \ (D_A = 9. 1 D_B = \) , then the output \ (9, 10 \) .
Other cases, no solution, then output \ (--1 \) .
By Code
/*
Status
Accepted
Time
31ms
Memory
12kB
Length
309
Lang
GNU G++11 5.1.0
RemoteRunId
67064706
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x, y;
cin >> x >> y;
if(x == y)
cout << x * 10 << " " << y * 10 + 1;
else if(x + 1 == y)
cout << x << " " << y;
else if(x == 9 && y == 1)
cout << "9 10";
else
cout << -1;
return 0;
}