当前位置:网站首页>Openjudge noi 1.13 14: find the 3 digits that meet the conditions

Openjudge noi 1.13 14: find the 3 digits that meet the conditions

2022-06-10 04:34:00 Junyi_ noip

【 Topic link 】

OpenJudge NOI 1.13 14: Seek to satisfy the condition 3 digit

【 Topic test site 】

1. enumeration

2. Digital split

【 Their thinking 】

The overall idea is enumeration .
x From small to large , x 2 x^2 x2 For this perfect square number . The result is three digits , therefore x The minimum value of is 10, x 2 x^2 x2 Less than the maximum 1000.
Each cycle , First seek x 2 x^2 x2 Get a complete square number , Then do a numerical split on this number , Split it into bits , ten , Hundred bit . Judge whether two of the three digits are the same .
If the number is conditional , Count .
If the count reaches n, Then output the n A number that satisfies the condition .

【 Solution code 】

solution 1: enumeration

#include <iostream>
using namespace std;
int main()
{
    
    int n, i = 0, x = 10, num, g, s, b;
    cin >> n;
    for(int x = 10; x*x < 1000; x++)
    {
    
        num = x*x;// A perfect square number 
        g = num%10;// bits 
        s = num/10%10;// ten 
        b = num/100;// Hundred bit 
        if(g == s || g == b || s == b)// If there is 2 Same bit 
        {
    
        	++i;// Numbers num It's No i Eligible numbers 
            if(i == n)
            {
    
                cout << num;
                return 0;
            }
        }
    }
    return 0;
}
原网站

版权声明
本文为[Junyi_ noip]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100433079631.html