Educational Codeforces Round 84 (Div. 2)

Educational Codeforces Round 84 (Div. 2)

读题读题读题+脑筋急转弯 = =。

A. Sum of Odd Integers

奇奇为奇,奇偶为偶,所以n,k奇偶性要相同。

由求和公式得k个不同奇数组成的最小数为k2,所以n≥k2

#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    if((n-k)%2==0&&n>=1LL*k*k)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
int main()
{
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}
View Code

B. Princesses and Princes

先模拟,后贪心。

#include <bits/stdc++.h>
using namespace std;
const int M=1e6;
void solve(){
    int n;cin>>n;
    bool prin[n+1]={0};
    bool dau[n+1]={0};
    vector<int> v[n+1];
    for(int i=1;i<=n;i++){
        int k;cin>>k;
        for(int j=0;j<k;j++){
            int t;cin>>t;
            v[i].push_back(t);
        }
    }
    for(int i=1;i<=n;i++){
        for(int j:v[i]){
            if(!prin[j]){
                dau[i]=prin[j]=true;
                break;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(!dau[i]){
            for(int j=1;j<=n;j++){
                if(!prin[j]){
                    cout<<"IMPROVE\n";
                    cout<<i<<' '<<j<<"\n";
                    return;
                }
            }
        }
    }
    cout<<"OPTIMAL\n";
}
int main()
{
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}
View Code

C. Game with Chips

先把所有点移至一角,然后遍历整个方块。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    string ans;
    ans+=string(n-1,'D');
    ans+=string(m-1,'R');
    for(int i=0;i<m;i++){
        ans+=string(n-1,"UD"[i&1]);
        if(i!=m-1) ans+="L";
    }
    cout<<ans.size()<<"\n";
    cout<<ans<<"\n";
    return 0;
}
View Code

E. Count The Blocks

中间情况:i长块在n长数中有n-i+1种位置,左右两位各有9种可能,其余n-i-2位各10种可能,i长块本身10种可能。

边界情况:i长块有2种位置,左或右有9种可能,其余n-i-1位各10种可能,i长块本身10种可能。

全长情况:i长块有1种位置,i长块本身10种可能。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
ll qpow(ll a,ll b){
    ll ret=1;
    while(b>0){
        if(b&1) ret=ret*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ret;
}
int main()
{
    int n;cin>>n;
    for(int i=1;i<n;i++){
        ll sum=0;
        sum+=2*9*10*qpow(10,n-i-1)%mod,sum%=mod;//边界情况
        sum+=(n-i-1)*9*10*9*qpow(10,n-i-2)%mod,sum%=mod;//中间情况
        cout<<sum<<" ";
    }
    cout<<"10"<<"\n";
    return 0;
}
View Code

  

猜你喜欢

转载自www.cnblogs.com/Kanoon/p/12558370.html