题解:P12184 [蓝桥杯 2025 省 Python A] 偏蓝

· · 题解

题目传送门

思路1

直接暴力枚举所有 r,g,b, 复杂度 O(n^3)。

其中 n=256。

思路2

只枚举 b。 其余 r,g 个数为 b^2。

代码

#include<bits/stdc++.h>
using namespace std;
int r,g,b;
long long ans;
int main(){
    for(b=0;b<=255;b++){
        ans+=(b*b);
    }
    cout<<ans;
    return 0;
}

再说一下, ans=5559680。