Codeforces Round #273 (Div. 2)

A. Initial Bet

思路:

题目写的和shi一样,本来意思很简单,题目说的曲里拐弯的,就是看加起来能不能被5整除,由于都是正整数,所以要特判0的情况

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

const int N = 100010;
const int MOD = 1000000007;

int a[N];

int main()
{
    int sum = 0;
    for (int i = 1; i <= 5; i++) cin >> a[i], sum += a[i];
    int x = 0;
    x = sum / 5;

    if (sum % 5 != 0 || sum == 0) cout << -1 << endl;
    else cout << x << endl;

    return 0;
}

B. Random Teams

思路:

当m-1个队人数为1,另一个队人数为n-m+1时分数最大,当各个队人数接近即 n%m个队人数为n/m+1,m-n%m个队人数为n/m时分数最小

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

const int N = 100010;
const int MOD = 1000000007;

int a[N];

int main()
{
    LL n, m;
    scanf("%lld%lld", &n, &m);
    LL maxres = 0, minres = 0;
    maxres = (n - (m - 1)) * (n - (m - 1) - 1) / 2;
    //n%m个队是n/m+1,m-n%m个队是n/m
    minres = ((n % m) * ((n / m + 1) * (n / m) / 2)) + ((m - n % m) * ((n / m) * (n / m - 1) / 2));
    printf("%lld %lld\n", minres, maxres);
    return 0;
}

C. Table Decorations

思路:

不妨设a<b<c,则当c>=2*(a+b)时答案ans=a+b,当c<2*(a+b)时答案res=(a+b+c)/3 

这题记住结论得了,感觉结论还挺有用的

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

const int N = 100010;
const int MOD = 1000000007;

LL a[4];

int main()
{
    for (int i = 1; i <= 3; i++) cin >> a[i];
    sort(a + 1, a + 1 + 3);
    LL res = 0;
    if (a[3] >= 2 * (a[1] + a[2])) res = a[1] + a[2];
    else res = (a[1] + a[2] + a[3]) / 3;
    cout << res << endl;
    return 0;
}

 

上一篇:Codeforces Round #748 (Div. 3) E、D1、D2


下一篇:《数学练习》