个人赛
作者:互联网
D - D
找每个与最大的差值即可
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e4+7;
int a[N];
int main(){
int n;
cin>>n;
int max1=-1394933434;
ll sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>max1)max1=a[i];
}
for(int i=0;i<n;i++){
sum+=abs(a[i]-max1);
}
cout<<sum<<endl;
}
A - A
就问你这个序列是否有两种数字,且个数相等
我的没过
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e4+7;
int b[N];
int main(){
int n;
cin>>n;
set<int> a;
a.clear();
for(int i=0;i<n;i++){
int w;
cin>>w;
b[w]++;
a.insert(w);
}
if(a.size()==2)
for(set<int>::iterator it=a.begin();it!=a.end();it++){
for(set<int>::iterator t=a.begin();t!=a.end();t++){
if(*it==*t)continue;
else if(b[*it]==b[*t]){
cout<<"YES"<<endl;
cout<<*it<<" "<<*t<<endl;
return 0;
}
}
}
else cout<<"NO"<<endl;
}
别人的
#include <bits/stdc++.h>
using namespace std;
map<int,int>maple;
int main(void)
{
int n,x;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&x);
maple[x]++;
}
if(maple.size()>2)
puts("NO");
else
{
map<int,int>::iterator t1 = maple.begin();
map<int,int>::iterator t2 = maple.begin();t2++;
if(t1->second==t2->second)
{
puts("YES");
printf("%d %d\n",t1->first,t2->first);
}
else
puts("NO");
}
return 0;
}
标签:begin,cout,iterator,int,++,个人赛,maple 来源: https://www.cnblogs.com/1324a/p/13911926.html