标签:lin nullptr rac algorithm using mes 代码 scan else
比赛链接:https://codeforces.com/contest/1436
经过模拟计算,观察到
\(\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;
}
#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;
}
#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;
}
#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;
}
Codeforces Round #677 (Div. 3)【ABCDE】
标签:lin nullptr rac algorithm using mes 代码 scan else
原文地址:https://www.cnblogs.com/forward-985/p/13911062.html