[acm]乐师师范学院校赛题解-2020

开始太紧张了,我也不知为什么开始这么紧张,a题给我错6次,心态都炸了。做最后一题的时候也是,开始脑子一直没转过来就是一个很普通的筛,没有 / i 卡了很久,最后5分钟,发现了这个问题,心里默念,舒服了。

先把最简单的写了,剩下的以后有时间在写把,,

还是太菜了.

A: 好数对

我开始想的方法是可以过1e6,或者1e7数据的方法,然后写着急了wa了6次,我还以为不弄用这个方法,我现在从写了一次,一发就过了,还是太紧张了,哎,,

#include <bits/stdc++.h>
using namespace std;

int pre[1000005];
int a[1000005];
int cnt[1000005] = {0};

void f(int n)
{
    n = 1000005;

    pre[2] = 1;
    for(int i = 3; i < n ; i++){
        pre[i] =  pre[i - 1] + i - 1;
    }
}

void solve()
{
    int t;
    cin >> t;
    f(1);

    for(int i = 0 ; i < t ;  i++){
        cin >> a[i];
        cnt[ a[i] ]++;
    }

    int ans = 0;
    for(int i = 0 ; i < 1000005 ; i++){
        if( cnt[i] > 1 ){
            ans += pre[ cnt[i] ];
        }
    }

    cout << ans <<endl;

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

B: 设计网页

两个方法

法一:线性筛

有点大材小用

#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;
int a[1000005];
int prime[1000005];
bool st[N] = {false};
int cnt = 0;

void get_primes(int n)
{

    for(int i = 2 ; i <= n ; i++){
        if( !st[i] ) prime[cnt++] = i;
        for(int j = 0 ; prime[j] <= n / i; j++){

            st[ prime[j] * i ] = true;
            if( i % prime[j] == 0 ) break;
        }
    }

}
void solve()
{
    get_primes(N);
    int n;
    cin >> n;
    if( st[n] == true ){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

法二:判素数公式

#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;

bool is_p( int num )
{
    if(num ==2|| num==3 )   //两个较小数另外处理
        return 1 ;
    if( (num %6!= 1&&num %6!= 5) || num == 1)   //不在6的倍数两侧的一定不是质数
        return 0 ;
    for(int i= 5; i <= num / i; i+=6 )   //在6的倍数两侧的也可能不是质数
        if(num %i== 0||num %(i+ 2)==0)  //排除所有,剩余的是质数
            return 0 ;
    return 1 ;
}

void solve()
{

    int n;
    cin >> n;
    if( is_p(n) == false ){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

D.后缀语言

没什么好说的,直接写就完了,这个才是最签到的吧,,

#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;


void solve()
{
    int t;
    cin >> t;
    while(t--){

        string s;
        cin >> s;

        int len = s.length();

        if( s[len - 1] == 'o' ){
            cout << "FILIPINO" << endl;
        }
        else if( s[len - 1] == 'u' ){
            cout << "JAPANESE" << endl;
        }
        else if( s[len - 1] == 'a' ){
            cout << "KOREAN" << endl;
        }
    }


}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

G.最大公约数

#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;


void solve()
{
    int t;
    cin >> t;

    while(t --){
        int n ;
        cin >> n;

        if(n == 2 || n == 1){
            cout << 1 << endl;;
        }
        else{
            if( n%2 == 0 ){
                cout << n / 2<< endl;
            }
            else{
                cout << (n - 1) / 2 << endl;
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

H.最小公倍数

#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;

typedef long long ll;

void solve()
{
    ll b;
    cin >> b;
    ll cnt = 0;
    for(ll i = 1; i*i <= b; ++i) {
        if(b % i == 0) {
            ++cnt;
            if(b / i != i) ++cnt;
        }
    }
    cout << cnt << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

原文地址:https://www.cnblogs.com/hoppz/p/14165982.html