8.27

· · 个人记录

今日比赛8.27

::::::info[T1]{open}

U593635

:::::success[赛时代码&得分]

\color{green}{Accepted\not100tps}
#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;
}
:::::

::::::info[T2]{open}

T643661

:::::warning[题意]

题意分析:

有一个0-r的数轴,一开始每个位置都有一个人。\\下达n条指令:\\1.左移x步\\2.右移x步\\~\\如果移动到了边界,那就不动了,所以会有一些人重叠在一起。

问题:

请问最后是不是所有人都叠在一起了?
:::::warning[赛时代码&得分]
$$
\color{red}{Wrong Answer\not45tps}
$$
```cpp line-numbers
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
cout<<-1;
return 0;
}
```
:::::
:::::success[正确代码]
```cpp line-numbers#include<bits/stdc++.h>
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;
}
```
:::::
::::::

::::::info[T3]{open}

U593638

:::::success[赛时代码&得分]

\color{green}{Accepted\not100tps}
#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;
}
:::::

::::::info[T4]{open}

U593645

:::::warning[题意]

题意分析:

先求a数组的前缀和然后便利q次\\然后通过模拟样例找到的规律进行计算得出答案\\并用ans记录\\最后输出ans即可

::::: :::::warning[赛时代码&得分]

\color{red}{Wrong Answer\not20tps}
#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;
}

::::: :::::success[正确代码]

#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;
}
:::::

::::::info[T5]{open}

U593646

:::::warning[题意]

题意分析:

1.先将1-9依次入队\\2.先按顺序将队首取出,然后将扩展之后的数字添加到队尾\\3.第K次取出的数字就是答案

::::: :::::warning[赛时代码&得分]

\color{red}{Wrong Answer\not0tps}
此内容已被删除。(详见置顶帖)

::::: :::::success[正确代码]

#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;
}
:::::