码迷,mamicode.com
首页 > 其他好文 > 详细

[lsnu]2021寒假训练_第二场

时间:2021-01-15 11:49:12      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:c++   贪心   pre   +=   题目   ase   code   tps   ext   

A - Biorhythms

题目链接

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

int main()
{
    int cnt = 1;
    while(true){

        int p,e,i,d;
        cin >> p >> e >> i >> d;
        if( p == -1 ){
            break;
        }

        int te = d + 1;

        while(true){
            if( (te-p)%23 == 0 && (te - e)%28 ==0 && (te - i)%33 == 0 ){
                printf("Case %d: the next triple peak occurs in %d days.\n",cnt++,te-d);
                break;
            }
            te++;
        }
    }

    return 0;
}

B - System of Equations

题目链接

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

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

int main()
{
    int n,m;
    cin >> n >> m;
    int maxn = max(n,m);

    int cnt = 0 ;

    for(int i = 0 ; i <= maxn ; i++){
        for(int j = 0 ; j <= maxn ; j++){
            if( po(i) + j == n && po(j) + i == m ){
                cnt++;
                //cout << i << " "  << j <<endl;
            }
        }
    }

    cout <<cnt << endl;
    return 0;
}

C - Team

题目链接

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

int main()
{
    int n;
    cin >> n ;
    int cnt = 0;
    for(int i = 0; i < n ; i++){
        int a,b,c;
        cin >> a >> b >> c;
        if( a+b+c >=2 ){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

D - Magic, Wizardry and Wonders

题目链接

这个题用贪心做更好,我直接嗯模拟的,

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

int a[105];
int maxn,minn;
int n , k , l;


int main()
{
    cin >> n >> k >> l;
    ///偶数

    fill(a,a+n,1);

    if(n%2 == 0){
        maxn = n / 2 *l - n/2;
        minn = n / 2 - n/2 *l;
        if( k > maxn || k < minn ){
            cout << -1 << endl;
            return 0;
        }
        ///
        if( k < 0 ){
            int cnt = -1 * k;
            for(int i = 1; i < n ; i+=2 ){
                while( a[i] < l ){
                    if( cnt == 0 ) break;
                    a[i] ++;
                    cnt --;
                }
            }

        }
        else if(  k == 0){

        }
        else if( k > 0){
            int cnt = k;
            for(int i = 0; i < n ; i+=2 ){
                while( a[i] < l ){
                    if( cnt == 0 ) break;
                    a[i] ++;
                    cnt --;
                }
            }
        }

    }///odd
    else{
        maxn = ( n / 2 + 1 )* l - ( n >> 1 ) ;
        minn = ( n / 2 + 1 ) - (n / 2 ) *l;
       // cout << maxn << ‘ ‘<<minn << endl;
        if( k > maxn || k < minn ){
            cout << -1 << endl;
            return 0;
        }
        ///
        if( k < 1 ){
            int cnt = -1 * k + 1;
            for(int i = 1; i < n ; i+=2 ){
                while( a[i] < l ){
                    if( cnt == 0 ) break;
                    a[i] ++;
                    cnt --;
                }
            }

        }
        else if(  k == 1){

        }
        else if( k > 1){
            int cnt = k - 1;
            for(int i = 0; i < n ; i+=2 ){
                while( a[i] < l ){
                    if( cnt == 0 ) break;
                    a[i] ++;
                    cnt --;
                }
            }
        }


    }
    for(int i = 0 ; i < n ; i++){
            cout << a[i] ;
            if( i != n -1 ) cout <<‘ ‘;
        }
        cout <<endl;



    return 0;
}

E - Games

题目链接

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

int main()
{
    int n ;
    int a[35][2];
    cin >> n;

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

    int ans = 0;

    for(int i = 0 ; i < n ; i++){
        for(int j = 0; j < n ; j++){

            if( i != j && a[i][0] == a[j][1] ){
                ans ++;
                //cout << i << ‘ ‘ << j << ‘ ‘ << endl;
            }

        }
    }

    cout << ans<< endl;

    return 0;
}

F - Encryption (easy)

题目链接


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

const int maxn = 1e5 + 5;
int a[maxn];
long long dp[maxn];

int main()
{
    int n,p;

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

    dp[0] =  a[0];
    for(int i = 1; i < n ; i++ ){
        dp[i] = dp[i - 1] + a[i];
    }

    int ans = 0;
    for(int i = 1 ; i < n ; i++){
        int x = dp[i - 1] % p;
        int y = ( dp[n-1] - dp[i - 1] ) % p;
        if( x + y > ans  ){
            ans = x + y;
        }
    }

    cout << ans <<endl;
    return 0;
}

[lsnu]2021寒假训练_第二场

标签:c++   贪心   pre   +=   题目   ase   code   tps   ext   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!