当前位置:   article > 正文

URAL - 2031 Overturned Numbers (枚举)_numbers2031

numbers2031

Little Pierre was surfing the Internet and came across an interesting puzzle:
在这里插入图片描述
What is the number under the car?
It took some time before Pierre solved the puzzle, but eventually he understood that there were overturned numbers 86, 88, 89, 90, and 91 in the picture and the answer was the number 87.
Now Pierre wants to entertain his friends with similar puzzles. He wants to construct a sequence of n numbers such that its overturning produces a consecutive segment of the positive integers. Pierre intends to use one-digit integers supplemented with a leading zero and two-digit integers only. To avoid ambiguity, note that when the digits 0, 1, and 8 are overturned, they remain the same, the digits 6 and 9 are converted into each other, and the remaining digits become unreadable symbols.
Input
The only line contains the number n of integers in a sequence (1 ≤ n ≤ 99).
Output
If there is no sequence of length n with the above property, output “Glupenky Pierre” (“Silly Pierre” in Russian). Otherwise, output any of such sequences. The numbers in the sequence should be separated with a space.
Samples
input
2
99
output
11 01
Glupenky Pierre
问题链接:http://acm.timus.ru/problem.aspx?space=1&num=2031
问题简述:输入n,如果可能的话输出翻转过来是相邻数字的序列,如果不能输出Glupenky Pierre
问题分析:n小于4才有解,所以枚举4种情况即可。注意输出个位数是要在前面加个0(以字符串形式输出即可)
AC通过的C++语言程序如下:

#include <iostream>
#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <climits>

#include <queue>
#include<vector>
using namespace std;

const int N=105;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    switch(n)
    {
    case 1:
        cout<<"01";
        break;
    case 2:
        cout<<11<<" "<<"01";
        break;
    case 3:
        cout<<16<<" "<<"06"<<" "<<68;
        break;
    case 4:
        cout<<16<<" "<<"06"<<" "<<68<<" "<<88;
        break;
    default:
        cout<<"Glupenky Pierre";
        break;
    }
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/75430
推荐阅读
相关标签
  

闽ICP备14008679号