Codeforces Round #666 (Div. 2)

哎太菜了就做出2个题掉了19分~~

A - Juggling Letters

统计一下每个字母出现的次数,由于最后要平均分配到每个数组中那么每个字母出现次数应该是n的倍数

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int cnt[30];
int main()
{
    IO;
    int T;
    cin>>T;
    while(T--)
    {
        memset(cnt,0,sizeof cnt);
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            string s;
            cin>>s;
            for(auto t:s) cnt[t-'a']++;
        }
        bool ok=1;
        for(int i=0;i<26;i++)
            if(cnt[i]%n) 
            {
                ok=0;
                break;
            }
        if(ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

B - Power Sequence

这题打了个暴力,玄学复杂度不知道怎么过的

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=100010;
const ll maxn=1e17;
ll a[N];
int main()
{
    IO;
    int n;
    cin>>n;
    ll maxa=0;
    for(int i=0;i<n;i++) 
    {
        cin>>a[i];
        maxa=max(maxa,a[i]);
    }
    sort(a,a+n);
    ll res=maxn;
    for(int i=1;i<=100000;i++)
    {
        ll cnt=abs(a[0]-1);
        ll p=1;
        bool ok=1;
        for(int j=1;j<n;j++)
        {
            if(p>maxn/i)
            {
                ok=0;
                break;
            }
            p=p*i;  
            cnt+=abs(p-a[j]);
        }
        if(ok) res=min(res,cnt);
    }
    cout<<res<<endl;
    return 0;
}

C - Multiples of Length

非常好的思维题,没有想到啊。。。
先把1~n-1的数全部变成n的倍数,可以这样a[i]+a[i]*(n-1)一定是n的倍数。然后将最后一个数变成0,第三部将整个数组消为0

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010;
int n,a[N];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    if(n==1)
    {
        cout<<1<<' '<<1<<'\n'<<-a[1]<<'\n';
        cout<<1<<' '<<1<<"\n0\n";
        cout<<1<<' '<<1<<"\n0\n";
    }
    else
    {
        cout<<1<<' '<<n-1<<'\n';
        for(int i=1;i<=n-1;i++) cout<<1ll*a[i]*(n-1)<<' ';
        cout<<'\n'<<n<<' '<<n<<'\n';
        cout<<-a[n];
        cout<<'\n'<<1<<' '<<n<<'\n';
        for(int i=1;i<=n;i++)
        {
            if(i==n) cout<<0<<' ';
            else cout<<-1ll*a[i]*n<<' ';
        }
    }
    return 0;
}

考试的时候想的是先把前一半len1变成n的倍数,然后把后一半len2变成n的倍数,对于加数能否变成n的倍数好像还不确定,现在要求 a i + k 1 l e n 1 = k 2 n a_i+k_1len_1=k_2n ai+k1len1=k2n k 1 l e n 1 + k 2 n = a i k_1len_1+k_2n=a_i k1len1+k2n=ai根据扩展欧几里得算法可以求 k 1 l e n 1 + k 2 n = g c d ( l e n 1 , n ) k_1len_1+k_2n=gcd(len_1,n) k1len1+k2n=gcd(len1,n)如果 a i % g c d ( l e n 1 , n ) a_i \% gcd(len_1,n) ai%gcd(len1,n)不为0那么无解,然后看了一下D发现好像是NIM游戏(后来证明是贪心),然后就不想看了就睡觉了。
不过看完题解发现如果 l e n 1 = n − 1 len_1=n-1 len1=n1,那么 g c d ( l e n 1 , n ) = 1 gcd(len_1,n)=1 gcd(len1,n)=1就不存在无解情况了。

D - Stoned Game

双方每次都选择当前石子数目最多的一堆即是最优方案。可以用优先队列模拟取石子过程。下面代码参考YeHosea大佬题解
一堆最多的石子超过总数一半先手必胜,如果未超过分奇偶讨论即可
whd大佬打表找规律结论与下述代码一样

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=110;
int n,a[N];
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n;
        int maxa=0;
        int s=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            s+=a[i];
            maxa=max(maxa,a[i]);
        }
        if(s-maxa<maxa||s%2==1) cout<<"T"<<endl;
        else cout<<"HL"<<endl;
    }
    return 0;
}

补题的时候发现这次div2并不是太难,只是思维题较多,需要静下心来思考。
要加油哦~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值