今日比赛8.27
T1
U593635
赛时代码&得分
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int a,b,c;
cin>>a>>b>>c;
cout<<c<<" "<<a<<" "<<b;
return 0;
}T2
T643661
题意
题意分析:
问题:
请问最后是不是所有人都叠在一起了?
赛时代码&得分
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
cout<<-1;
return 0;
}正确代码
using namespace std;
long long m,s=0,s1;
int n;
bool f=0;
int main(){
cin>>m>>n;
s1=m;
for(int i=1;i<=n;i++){
long long x;
cin>>x;
s+=x;
s1+=x;
if(s<0) s=0;
if(s1<0) s1=0;
if(s>m) s=m;
if(s1>m) s1=m;
}
if(s==s1) cout<<s;
else cout<<-1;
return 0;
}T3
U593638
赛时代码&得分
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,k;
cin>>n>>k;
if(n>=k){
cout<<min(n%k,abs(k*(n/k+1)-n));
return 0;
}
if(k-n<n) cout<<abs(n-k);
else cout<<n;
return 0;
}T4
U593645
题意
题意分析:
赛时代码&得分
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200005],x;
int main(){
ll n,q;
cin>>n>>q;
for(ll i=1;i<=n;i++) cin>>a[i];
for(ll i=1;i<=q;i++){
ll ans=0;
cin>>x;
for(ll j=1;j<=n;j++)
ans+=abs(a[j]-x);
cout<<ans<<endl;
}
return 0;
}正确代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,q,x,a[N],s[N];
int main() {
cin>>n>>q;
s[0]=0;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)s[i]=a[i]+s[i-1];
while(q--){
cin>>x;
ll pos=lower_bound(a+1,a+1+n,x)-a;
pos--;
ll ans=0;
ans+=x*pos-s[pos];
ans+=s[n]-s[pos]-(n-pos)*x;
cout<<ans<<"\n";
}
return 0;
}T5
U593646
题意
题意分析:
赛时代码&得分
此内容已被删除。(详见置顶帖)正确代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll k;
cin>>k;
queue<ll>q;
for(ll i=1;i<=9;i++) q.push(i);
ll cnt=0;
while(!q.empty()){
ll x=q.front();
q.pop();
cnt++;
if(cnt==k){
cout<<x<<endl;
break;
}
for(ll y=(x%10)-1;y<=(x%10)+1;y++){
if(y<0||y>9) continue;
q.push(x*10+y);
}
}
return 0;
}