19.5.17 CF #563 (Div. 2) 解题报告

  • 这场a b c全有3k+的人做出来, 罚时有点多了, 难受.

A. Ehab Fails to Be Thanos

  • 排序后判断前后两半是否相等
  • ac代码
/*************************************************************************
    > File Name: a.cpp
    > Author: Wqr_
    > Mail: xueduanwei@126.com
    > Created Time: 2019年06月03日 星期一 21时55分16秒
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#define iofuck std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int nmax = 1000 + 5;
int n;
int a[nmax * 2];
int main(){
    iofuck;
    cin >> n;
    for(int i = 0; i < 2 * n; i++){
        cin >> a[i];
    }
    sort(a, a + 2 * n);
    ll sum1 = 0, sum2 = 0;
    for(int i = 0; i < n; i++){
        sum1 += a[i];
    }
    for(int i = n; i < 2 * n; i++){
        sum2 += a[i];
    }
    if(sum1 != sum2){
        for(int i = 0; i < 2 * n; i++){
            cout << a[i] << " ";
        }
    }else{
        cout << -1 << endl;
    }
    return 0;
}

B. Ehab Is an Odd Person

  • 如果同时有奇数后偶数就对整体排序后输出, 否则原样输出
  • ac代码
/*************************************************************************
    > File Name: b.cpp
    > Author: Wqr_
    > Mail: xueduanwei@126.com
    > Created Time: 2019年06月03日 星期一 22时09分33秒
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#define iofuck std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int nmax = 1e5 + 5;
int n;
int a[nmax];
int b[nmax];
bool book[nmax];
int main(){
    iofuck;
    cin >> n;
    bool flag1 = 0;
    bool flag2 = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2)  flag2 = 1;
        else flag1= 1;
    }
    if(flag1 && flag2)
        sort(a, a + n);
    for(int i = 0; i < n; i++){
        cout << a[i] << " ";
    }
    return 0;
}

C. Ehab and a Special Coloring Problem

  • 对每个素数和素数倍数赋值, 不是的附为1
  • 具体见代码
  • ac代码
/*************************************************************************
    > File Name: c.cpp
    > Author: Wqr_
    > Mail: xueduanwei@126.com
    > Created Time: 2019年06月03日 星期一 22时41分12秒
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#define iofuck std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
int n;
const int nmax = 1e5 + 5;
bool mark[nmax];
vector<int> per;
void prime()
{
    for(int i = 2; i < nmax; i++){
        if(mark[i]) continue;
        per.push_back(i);
        for(int j = 2; j * i < nmax; j++){
            mark[j * i] = 1;
        }
    }
}
int main(){
    prime();
    cin >> n;
    int ans[nmax];
    int flag = 1;
    for(auto tmp : per){
        for(int i = 1; i * tmp < nmax; i++){
            ans[i * tmp] = flag;
        }
        flag++;
    }
    for(int i = 2; i <= n; i++){
        cout << ans[i] << " ";
    }
    return 0;
}