Codeforces Round #662 (Div. 2) 题解.

Codeforces Round #662 (Div. 2) 题解

  • A. Rainbow Dash, Fluttershy and Chess Coloring

  • 阅读题,题意比较难理解,但是读懂题多画几个例子之后就能发现答案其实就是 ans=n/2+1;

#include
using namespace std;

typedef long long ll;
typedef long double ld;
int t,n;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        int ans;
        if(n&1){
            ans=n/2+1;
        } else {
            ans=n/2+1;
        }
        cout<
  • B. Applejack and Storages
  • 统计一下个数,顺带记录一下2-4个的,4-6个的,6-8个的和8个以上的就行了
#include
using namespace std;

typedef long long ll;
typedef long double ld;
int t, n;
const int N = 1e5 + 10;
int a[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //cin >> t;
    //while (t--) {
        cin >> n;
        int n2 = 0, n4 = 0, n6=0,n8=0;
        memset(a, 0, sizeof(a));
        for (int i = 0; i < n; ++i) {
            int tmp;
            cin >> tmp;
            a[tmp]++;
            if (a[tmp] == 2) n2++;
            if (a[tmp] == 4) n2--, n4++;
            if(a[tmp]==6) n4--,n6++;
            if(a[tmp]==8) n6--,n8++;
        }
        int q;
        cin >> q;
        //cout<> op >> num;
            if (op == '+') {
                a[num]++;
                if (a[num] == 2) n2++;
                if (a[num] == 4) n4++, n2--;
                if(a[num]==6) n4--,n6++;
                if(a[num]==8) n6--,n8++;
            }
            else {
                a[num]--;
                if(a[num]==7) n8--,n6++;
                if(a[num]==5) n6--,n4++;
                if (a[num] == 3) n4--, n2++;
                if (a[num] == 1) n2--;
            }
            if(n8>=1){
                cout<<"YES\n";
                continue;
            }
            if(n6>=1){
                if(n6==1){
                    if(n4>=1 ||n2>=1){
                        cout<<"YES\n";
                        continue;
                    }else{
                        cout<<"NO\n";
                        continue;
                    }
                }else{
                    cout<<"YES\n";
                    continue;
                }
            }else{
                if(n4>=1){
                    if(n4==1){
                        if(n2>=2){
                            cout<<"YES\n";
                            continue;
                        }else {
                            cout<<"NO\n";
                            continue;
                        }
                    }else{
                        cout<<"YES\n";
                        continue;
                    }
                }else{
                    cout<<"NO\n";
                    continue;
                }
            }
        }
    //}
    return 0;
}
  • C. Pinkie Pie Eats Patty-cakes

  • 记录下个数,找到个数最多的几个,然后先排个数最多的那几个,计算下最大的最小距离就行了(比赛的时候傻逼了用二分去搜索答案,又是二分出锅qwq

#include
using namespace std;

typedef long long ll;
typedef long double ld;

const int N=1e5+10;
int t,n;
int a[N];
struct node{
    int id,num;
}p[N];

bool cmp(node a,node b)
{
    return a.num>b.num;
}

bool check(int x,int mn,int n1) //n1 mam
{
    if(x*(n1-1)+mn*(n1)<=n) return 1;
    else return 0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        memset(a,0,sizeof(int)*(n+1));
        int mam=0,mnum=0;
        for(int i=1;i<=n;++i){
            int tmp;
            cin>>tmp;
            a[tmp]++;
            mam=max(mam,a[tmp]);
        }
        for(int i=0;i<=n;++i){
            if(a[i]==mam) mnum++;
        }
        int ans=(n-mnum*mam)/(mam-1)+mnum-1;
        cout<

DEF明天起来补叭

你可能感兴趣的:(codeforces)