zoukankan      html  css  js  c++  java
  • CF1225A Forgetting Things

    CF1225A Forgetting Things

    洛谷评测传送门

    题目描述

    Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation a + 1 = ba+1=b with positive integers aa and bb , but Kolya forgot the numbers aa and bb . He does, however, remember that the first (leftmost) digit of aa was d_ad**a , and the first (leftmost) digit of bb was d_bd**b .

    Can you reconstruct any equation a + 1 = ba+1=b that satisfies this property? It may be possible that Kolya misremembers the digits, and there is no suitable equation, in which case report so.

    输入格式

    The only line contains two space-separated digits d_ad**a and d_bd**b ( 1 leq d_a, d_b leq 91≤d**a,d**b≤9 ).

    输出格式

    If there is no equation a + 1 = ba+1=b with positive integers aa and bb such that the first digit of aa is d_ad**a , and the first digit of bb is d_bd**b , print a single number -1−1 .

    Otherwise, print any suitable aa and bb that both are positive and do not exceed 10^9109 . It is guaranteed that if a solution exists, there also exists a solution with both numbers not exceeding 10^9109 .

    输入输出样例

    输入 #1复制

    输出 #1复制

    输入 #2复制

    输出 #2复制

    输入 #3复制

    输出 #3复制

    输入 #4复制

    输出 #4复制

    题解:

    题目翻译人赶来发布第一篇题解。

    CF​本场本题被hack了?

    是一道分类讨论的题目。

    用草纸模拟一下,我们发现题意有这么几个性质:

    首先,假如(d_b>d_a+1),那么肯定是满足不了性质的。

    然后,假如(d_b<d_a),也肯定满足不了性质。注意,特殊地:如果(d_a=1,d_b=9),那么也可以满足性质,所以这样的情况被抛弃了。

    因为是SPJ。所以剩下的情况随便判一判就好了。

    注意细节一定要考虑全面。

    比如那组hack数据:9 9

    我一开始就没考虑到,导致hack成功。

    所以加了个补丁。就过了(我太菜了)

    #include<cstdio>
    using namespace std;
    int da,db;
    int main()
    {
        scanf("%d%d",&da,&db);
        if(db>da+1 || (db<da && da!=9))
        {
            printf("-1");
            return 0;
        }
        else if(da==9 && db==9)
        {
            printf("91 92");
            return 0;
        }
        else if(da==9 && db!=1)
        {
            printf("-1");
            return 0;
        }
        else if(da==9 && db==1)
        {
            printf("9 10");
            return 0;
        }
        else if(da+1==db)
        {
            printf("%d %d",da,db);
            return 0;
        }
        else
        {
            printf("%d %d",da*10+1,db*10+2);
            return 0;
        }
    }
    
  • 相关阅读:
    ROM定制开发教程-Android adb命令用法与实例解析
    Android内存优化—dumpsys meminfo详解
    adb命令查看手机应用内存使用情况
    【特征检测】BRISK特征提取算法
    焦虑症
    基于Lua的游戏服务端框架简介
    流量
    学习React Native必看的几个开源项目
    那些离开私企进入国企的人,现在都过得怎么样了?
    分布式系统中有关一致性的理解
  • 原文地址:https://www.cnblogs.com/fusiwei/p/11750199.html
Copyright © 2011-2022 走看看