Codeforces Round #662题解报告A~C

题目链接

A、Rainbow Dash, Fluttershy and Chess Coloring

水题,找找规律即可。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x7fffffff
const int N = 1e5 + 10;
const double PI= acos(-1.0);
ll ans[N],b[N];
int main(){
    
    
    int t;ll n;
    cin >> t;
    while(t--){
    
    
        cin >> n;
        cout << n/2+1 <<endl;
    }
    return 0;
}

B、Applejack and Storages

题意:给出n条边,再进行m次操作,每次操作可以加一条边或者拿走一条边,问剩下的能否组成一个正方形和一个矩形(矩形可以是正方形)。
思路:记录一下相同长度的边条数为4的个数,再记录一下相同长度的边条数为2的个数。当然,这里要考虑一下如果某个长度的边有六条,那么可以记作一个4条和一个2条(即一个正方形和一个矩形的两条边)。最后判断一下即可,具体看代码。
这个题当场没得做出来,看了看题解都用的各种stl各种算法,但还是找到思路,尝试了好多遍找出的解题方法,其实只需要用普通数组模拟一下即可。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x7fffffff
const int N = 1e5 + 10;
const double PI= acos(-1.0);
ll a[N],b[N];
int main()
{
    
    
    int n,x,maxx=-1;
    char ch;
    int f1=0,f2=0,f3=0;
    cin >> n;
    for(int i=0; i<n; i++)
    {
    
    
        cin >> x;
        maxx = max(maxx,x);
        a[x]++;
    }
    for(int i=0;i<=maxx;i++){
    
    
        f1 += a[i]/4;
        f2 += a[i]%4/2;
    }
    int sum=n;
    cin >> n;
    while(n--)
    {
    
    
        cin >> ch >> x;
        maxx = max(maxx,x);
        if(ch=='+'){
    
    
            f1 -= a[x]/4;
            f2 -= a[x]%4/2;
            a[x]++;
            sum++;
            f1 += a[x]/4;
            f2 += a[x]%4/2;
        }
        else{
    
    
            f1 -= a[x]/4;
            f2 -= a[x]%4/2;
            a[x]--;
            sum--;
            f1 += a[x]/4;
            f2 += a[x]%4/2;
        }
        if(sum<8)
        {
    
    
            cout << "NO" <<endl;
            continue;
        }
        if(f1>=2||(f1==1&&f2>=2))
            cout << "YES" <<endl;
        else cout << "NO" <<endl;
    }
    return 0;
}

C、Pinkie Pie Eats Patty-cakes

题意:给出一个序列,找一个排序方式使相同的数字之间的最小距离最大。
思路:参考了大佬的题解,这个是找到的讲解的最详细的。
其实要使最小距离最大,其实就是找出现最多的数字,把这个数字当成隔板,往里面填充数字。如果有多个数字出现次数最多且相等,那么就把这些相同的数捆绑当成隔板,然后先处理剩下的数,再加上这些出现次数相同的数的个数即可。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x7fffffff
const int N = 1e5 + 10;
const double PI= acos(-1.0);
const int mod = 1e9 + 7;
int a[N],vis[N],num[N];
int main()
{
    
    
    int t,n;
    cin >> t;
    while( t-- )
    {
    
    
        cin >> n;
        memset(vis,0,sizeof vis);
        int num=0,maxx=0;
        for(int i=1,x; i<=n; i++)
        {
    
    
            cin >> x;
            maxx=max(maxx,++vis[x]);
        }
        for(int i=1; i<=n; i++)
            if(vis[i]==maxx)
                num++;
        cout<< (n-maxx*num)/(maxx-1)+num-1 << endl;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_45949914/article/details/107883623
今日推荐