Codeforces Round #686 (Div. 3) ABCD

佬儿选的这套题真好,该有的坑我都踩了
[苦笑(bushi]

A.Special Permutation
https://codeforces.com/contest/1454/problem/A

题目大意:给定一个n,要求我们写出一个关于n的排列,使得a[i]!=i
input
2
2
5
output
2 1
2 1 5 3 4
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const LL N=10010,M=2*N;
int n,m;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        cout<<n<<" ";
        for(int i=1;i<n;i++)
            cout<<i<<" ";
        cout<<endl;
    }
    return 0;
}

B.Unique Bid Auction
https://codeforces.com/contest/1454/problem/B

没改N真的是疑惑我一整晚

题目大意:给定一个长度为n的数组a,让我们求这个数组中唯一的并且最小的下标的值
input
6
2
1 1
3
2 1 3
4
2 2 2 3
1
1
5
2 3 2 4 2
6
1 1 5 5 4 4
output
-1
2
4
1
2
-1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const LL N=200200;
int a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        map<int,int> mp;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
        int idx=-1;
        int minn=0x3f3f3f3f;
        for(int i=1;i<=n;i++)
            if(mp[a[i]]==1&&a[i]<minn)
            {
                idx=i;
                minn=a[i];
            }
        cout<<idx<<endl;
    }
    return 0;
}

C. Sequence Transformation
https://codeforces.com/contest/1454/problem/C

题目大意:给定一个长度为n的数组a,有一个删除操作可以执行任意次,问至少需要多少次就能够得到数组全是一样的数字?
删除操作是这样的:如果我们想留下x,那么任何x到下一个x之间如果存在非x的数字的时候都可以直接把这个区间删除了。
input
5
3
1 1 1
5
1 2 3 4 5
5
1 2 3 2 1
7
1 2 3 1 2 3 1
11
2 2 1 2 3 2 1 2 3 1 2
output
0
1
1
2
3
  1. 我们想要最小化删除区间的数量,那么对于每个数我们也希望他是出现的最少的
  2. 同时,我们必须注意到如果有>=2个数字是黏在一起的,那么我们只需要记录一个就行了,因为这里面没有别的数字不会影响操作次数
  3. 然后就是要考虑到如果是正常的段数--x--x--就是x的个数+1
  4. 但是如果是在边界上的话x--x--x--就是正常段数-1 --x--x--x 这样也需要再-1
  5. eg:本来这一段x--x--x是4的,但是遇上了两个边界,所以就变成了正常段数-1再-1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200200;
int a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        map<int,int> mp;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i-1]!=a[i]) mp[a[i]]++;
            else continue;
        }
        int minn=n+1;
        for(int i=1;i<=n;i++)
        {
            //cout<<i<<" "<<mp[i]<<endl;
            if(mp[i]!=0)
            {
                int res=mp[i]+1;
                if(a[1]==i) res--;
                if(a[n]==i) res--;
                minn=min(minn,res);
            }
        }
        cout<<minn<<endl;
    }
    return 0;
}

D. Number into Sequence
https://codeforces.com/contest/1454/problem/D

题目大意:给你一个整数n (n>1)。

你的任务是找到一个整数序列a1,a2,…,ak,使得:

每个ai严格大于1;
a1⋅a2⋅…⋅ak=n(即这个序列的乘积是n);
对于从1到k1的每个i,a[i+1]可被a[i]整除;
k是最大可能值(即该序列的长度是最大可能值)。
如果有几个这样的序列,任何一个都是可以接受的。可以证明,对于任何n>1的整数,总是存在至少一个有效序列。
input
4
2
360
4999999937
4998207083
output
1
2 
3
2 2 90 
1
4999999937 
1
4998207083 
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        LL x;
        cin>>x;
        LL n=x;
        vector<LL> v;
        map<LL,LL> mp;
        for(LL i=2;i<=x/i;i++)
        {
            if(x%i==0)
            {
                while(x%i==0)
                {
                    mp[i]++;
                    x/=i;
                }
                v.push_back(i);
            }
        }
        if(x>1)
        {
            mp[x]++;
            v.push_back(x);
        }
        //cout<<v.size()<<endl;
        LL maxn=0;
        LL flag=0;
        for(LL i=0;i<v.size();i++)
        {
            //cout<<v[i]<<" "<<mp[v[i]]<<endl;
            if(mp[v[i]]>maxn)
            {
                maxn=mp[v[i]];
                flag=v[i];
            }
        }
        cout<<maxn<<endl;
        LL res=1;
        for(LL i=1;i<=maxn-1;i++)
        {
            cout<<flag<<" ";
            res*=flag;
        }
        cout<<n/res<<endl;
    }
    return 0;
}
posted @ 2022-08-26 11:28  高尔赛凡尔娟  阅读(16)  评论(0编辑  收藏  举报