当前位置:网站首页>Openjudge noi 2.1 1749: Digital Square

Openjudge noi 2.1 1749: Digital Square

2022-07-06 07:14:00 Jun Yi_ noip

【 Topic link 】

OpenJudge NOI 2.1 1749: Number squares

【 Topic test site 】

1. enumeration

【 Their thinking 】

Solve equations by enumerating

  • enumerable object : a 1 , a 2 , a 3 a_1,a_2,a_3 a1,a2,a3
  • Enumeration range : 0 ≤ a 1 , a 2 , a 3 ≤ n 0\le a_1, a_2, a_3 \le n 0a1,a2,a3n
  • Enumeration condition :
    ( a 1 + a 2 ) % 2 = 0 (a_1+a_2)\%2 = 0 (a1+a2)%2=0
    ( a 2 + a 3 ) % 3 = 0 (a_2+a_3)\%3 = 0 (a2+a3)%3=0
    ( a 1 + a 2 + a 3 ) % 5 = 0 (a_1+a_2+a_3)\%5 = 0 (a1+a2+a3)%5=0

Enumerate the qualified a 1 , a 2 , a 3 a_1,a_2,a_3 a1,a2,a3, choice a 1 + a 2 + a 3 a_1+a_2+a_3 a1+a2+a3 The largest group .

【 Solution code 】

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    int n, mx = 0;//mx:a1+a2+a3 The maximum of  
    cin >> n;
    for(int a1 = 0; a1 <= n; ++a1)
        for(int a2 = 0; a2 <= n; ++a2)
            for(int a3 = 0; a3 <= n; ++a3)
            {
    
                if((a1+a2)%2 == 0 && (a2+a3)%3 == 0 && (a1+a2+a3)%5 == 0)
                    mx = max(mx, a1+a2+a3);
            }
    cout << mx;
    return 0;
}
原网站

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