[lsnu]2021寒假_第一场

A - Perfect Cubes

题目链接

还是想的hash去重出问题了2333开始用(i+k+j) * 13去重,但是忘了有多个(i+j+k)的可能,最后发现
-i * 13 + j *3 + k * 1-可以用这种去重,后面队友说可以直接线性做, --也坑了一次,最后代码如下

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

int n;

int po(int k)
{
    return k*k*k;
}

int main()
{
    cin >> n;
    ///cube

    int  cnt = 0;
    for(int i = 6 ; i <= n ; i++){
        ///triple

        for(int j = 2; j <= n ; j++){

            for(int k = j; k <=n ; k++){

                for(int t = k; t <= n; t++){

                    if( po(i) == po( k) + po( j) + po( t) ){

                        printf( "Cube = %d, Triple = (%d,%d,%d)
",i,j,k,t);

                    }
                }
            }
        }

    }
   // cout << mypow(3,2);

    return 0;
}

B - Second Order Statistics

题目链接

#include <iostream>
#include <algorithm>
using namespace std;


int a[1000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n ;i ++){
        cin >> a[i];
    }
    sort(a,a+n);

    int te = a[0];

    for(int i = 0; i <n ; i++){
        if( a[i] > te ){
            cout << a[i] << endl;
            return 0;
        }
    }
    cout << "NO" << endl; 

    return 0;
} 

C - Panoramix's Prediction

题目链接

#include <iostream>
#include <algorithm>
using namespace std;

int st[1000000] = {0};
int prime[1000000];
int cnt =0;
void is_prime(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[ i * prime[j] ] = 1;
            if( i % prime[j] == 0 ) break;
        }
    }
    return ;
}



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

    int a,b;
    cin >> a >> b;
    is_prime(55);

    int te = lower_bound(prime,prime+cnt,a) - prime;
    if( b == prime[te + 1 ] ){
        cout << "YES" <<endl;
    }
    else{
        cout << "NO" <<endl;
    }

    return 0;
}

D - Game Outcome

题目链接

#include <iostream>
#include <algorithm>
using namespace std;

int a[35][35];
int n;

bool f(int i ,int j)
{

    int tey = 0;
    int tex = 0;
    for(int k = 0 ; k < n ; k++){
        tey += a[k][j];
    }
    for(int k = 0 ; k < n ; k++){
        tex += a[i][k];
    }

    if( tex < tey) return true;
    else return false;
}

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

    cin >> n;

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

    if( n == 1 ){
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;
    for(int i = 0 ; i < n ; i ++){
        for(int j  = 0 ; j < n ; j ++){
            if( f(i,j) ){
                ans++;
            }
        }
    }

    cout <<ans << endl;

    return 0;
}

E - Perform the Combo

题目链接

这个题稍微难一点,用差分就好了,我开1e6的数据,就不行说超时,可能是memset超了吧

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn = 2e5 + 5;
int w[27] = {0};
char a[maxn];
int  am[maxn];
int ch[maxn];
int qi[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 0 ;
    cin >> t;
    while(t --)
    {
        int n,m;
        cin >> n >> m;

        memset(w,0,sizeof(w));
        memset(a,0,sizeof a );
        memset(am,0,sizeof am);
        memset(ch,0,sizeof ch);
        for(int i = 0; i < n ; i ++)
        {
            cin >> a[i];
        }

        for(int i = 0; i < m ; i++)
        {
            cin >> am[i];
        }
        ///差分
        for(int i = 0 ; i < m ; i++){
            ch[0] ++;
            ch[am[i]] --;
        }
        ch[0]++;

        ///前缀和
        qi[0] = ch[0];
        for(int i = 1 ; i < n ; i++){
            qi[i] = qi[i - 1] + ch[i];
        }

        ///
        for(int i = 0; i < n ; i++){
            w[ a[i] - 'a' ] += qi[i];
        }

        for(int i = 0 ; i < 26 ; i++){
            cout << w[i] << " ";
        }
        cout<< endl;
    }
    return 0;
}

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