其他分享
首页 > 其他分享> > Codeforces Round #677 (Div. 3)【ABCDE】

Codeforces Round #677 (Div. 3)【ABCDE】

作者:互联网

比赛链接:https://codeforces.com/contest/1436

A.Reorder

题解

经过模拟计算,观察到
\(\sum_{i=1}^n \sum_{j=i}^n \frac{a_j}{j}=\sum_{i=1}^n a_i\)
判断每个n个数的和sum与m是否相等即可

代码

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);//关闭cin与scanf同步
    cin.tie(nullptr);
    int t;cin>>t;
    while(t--)
    {
        int n,m,x,sum=0;
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            cin>>x;
            sum+=x;
        }
        if(sum==m)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

B.Yet Another Bookshelf

题解

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            sum += x;
        }
        cout << (sum == m ? "YES" : "NO") << "\n";
    }
    return 0;
}

A.Reorder

题解

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            sum += x;
        }
        cout << (sum == m ? "YES" : "NO") << "\n";
    }
    return 0;
}

A.Reorder

题解

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            sum += x;
        }
        cout << (sum == m ? "YES" : "NO") << "\n";
    }
    return 0;
}

标签:false,int,题解,sum,677,ABCDE,cin,Div,include
来源: https://www.cnblogs.com/forward-985/p/13911062.html