Codeforces Round #666 (Div. 2)(ABCD题解),E看情况再补

A. Juggling Letters

题意:

给你n个串,可以进行一种操作。
把一个字母移到任意地方。

最后是否可以使所有n个串都相同。

思路:

统计字母就可。(老套路了)

AC

#include <iostream>
#include <string>
#include <cstring>
#define mst(x,a) memset(x,a,sizeof(x))
using namespace std;
int a[26];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        string s;//cin>>s;
        mst(a,0);
        for(int i=1; i<=n; i++){
            cin>>s;
            int len=s.size();
            for(int j=0; j<len; j++)a[s[j]-'a']++;
        }
        int f=1;
        for(int i=0; i<26; i++){
            if(a[i]%n!=0)f=0;
        }
        if(f)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

B. Power Sequence

题意:

给你一个数组,进行最小的操作,使得它变成一个等比数列(q>=1)
一次操作是+1/-1

思路:

  1. 当n很小时,q(公比)可能的情况很多。
  2. 相反,当n很大时(假如1e5,上届),q只可能为1.
  3. 所以两层循环暴力是可以的。

反思:

  1. 本题fst在了界限分析。(我取了1e9被hack,赛后取1e10过了)

AC

#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const ll up=1e10;
ll a[maxn];
vector<ll>p[maxn];
void init(){
    for(ll i=1; i*i<=up; i++){
        ll cur=1,tot=1;
        while(cur<=up&&tot<=1e5){
            p[i].push_back(cur);
            cur*=i;
            tot++;
        }
        p[i].push_back(cur);
    }
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    init();
    ll n;cin>>n;
    for(int i=1; i<=n; i++)cin>>a[i];
    sort(a+1,a+1+n);
    ll ans=1e18,tmp=0;
    for(int j=1; j<=n; j++)tmp+=abs(a[j]-1);
    ans=min(ans,tmp);
    int i=2;
    while(1){
        ll cur=lower_bound(p[i].begin(),p[i].end(),up)-p[i].begin();
        ///对于power2,第34个正好大于1e10.
        if(cur<n)break;
        tmp=0;
        for(int j=1; j<=n; j++)tmp+=abs(a[j]-p[i][j-1]);
        ans=min(ans,tmp);
        i++;
    }
    cout<<ans<<endl;
    return 0;
}/*
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1000000000
*/

C. Multiples of Length

题意:

给你一个数组。
每次都可以选择一个区间(长度为len),对这个区间加一个数x,x满足x%len=0.
可以证明三次操作都可以变为0.问怎样操作。

思路:见代码,直接输出答案即可。

AC

#include <iostream>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll a[maxn];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)cin>>a[i];
    if(n==1){
        cout<<1<<' '<<1<<endl;
        cout<<1<<endl;
        cout<<1<<' '<<1<<endl;
        cout<<1<<endl;
        cout<<1<<' '<<1<<endl;
        cout<<-(a[1]+2)<<endl;
    }else {
        cout<<1<<' '<<n-1<<endl;
        for(int i=1; i<=n-1; i++)cout<<(a[i]*(n-1) )<<' ';
        cout<<endl;
        cout<<n<<' '<<n<<endl;
        cout<<a[n]*(n-1)<<endl;
        cout<<1<<' '<<n<<endl;
        for(int i=1; i<=n; i++)cout<<-(a[i]*n)<<' ';
        cout<<endl;
    }
    return 0;
}

D. Stoned Game

题解:

博弈贪心

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值