有多少人输入的时候跟我写的一样的

B3957 [GESP202403 三级] 完全平方数

MLSY_OIer_ZXL @ 2024-09-04 17:56:09

我输入的时候用的是for循环,但写成了这样。。。。。。

 for (int i = 0 ; i <= n ; i++)

此外,全WA求助!!!


by MLSY_OIer_ZXL @ 2024-09-04 17:57:18

@ron120719 这是我的Code

#include <iostream>
#include <cmath>
using namespace std;

const int MAX_LIMIT = 200000;
const int MAX_SQRT = 447;

int main() {
    int n;
    cin >> n;

    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    bool perfectSquares[MAX_LIMIT + 1] = {false};
    for (int i = 0; i <= MAX_SQRT; ++i) {
        int sq = i * i;
        if (sq <= MAX_LIMIT) {
            perfectSquares[sq] = true;
        }
    }

    int count = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int sum = a[i] + a[j];
            if (sum <= MAX_LIMIT && perfectSquares[sum]) {
                ++count;
            }
        }
    }

    cout << count << endl;

    return 0;
}

by cuixizhou @ 2024-09-06 20:51:00

额,这么长吗?(好奇ing)

我的是不是太短了......

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[1005],g=0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) if(int(sqrt(a[i]+a[j]))==sqrt(a[i]+a[j]*1.0)) g++;
    cout<<g;
    return 0;
}

by zzj_340231 @ 2024-09-06 21:57:38

@ron120719 自己@自己


by MLSY_OIer_ZXL @ 2024-09-06 22:54:46

@cuixizhou 你的格式太难看了,都挤在一起


by cuixizhou @ 2024-09-07 17:46:38

@ron120719 嘿嘿,那我展开:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[1005],g=0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) 
          for(int j=i+1;j<=n;j++) 
                if(int(sqrt(a[i]+a[j]))==sqrt(a[i]+a[j]*1.0))
                    g++;
    cout<<g;
    return 0;
}

by MLSY_OIer_ZXL @ 2024-09-08 15:01:43

现在舒服了

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, a[1005], g = 0;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (int(sqrt(a[i] + a[j])) == sqrt(a[i] + a[j] * 1.0)) {
                g++;
            }
        }
    }

    cout << g << endl;

    return 0;
}

by yimixiao_qfq @ 2024-09-10 21:54:39

@ron120719 me too!


|