Codeforces Round #810 (Div. 2) (A~C)

1711A

题意:

给定n

使得序列 p [1,2,3····n] pi / i 的值最小

思路:

让相邻两数互质

Code:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 200010;

ll n, k, res;

ll a[N];

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
        a[i] = i;
    for (int i = 1; i <= n-1; i += 2)
    {
        a[i]=i+1;
        a[i+1]=i;
    }
    if (n==1)
    {
        cout << 1 << endl;
        return;
    }
    if (n % 2==1)
    swap(a[1], a[n]);
    for (int i = 1; i <= n; i ++)
        printf("%ld ", a[i]);
    printf("\\n");
}
int main()
{
    int t;
    cin >> t;
    while (t --)
    {
        solve();
    }

    system("pause");

    return 0;
}

1711B

题意:

n个不高兴值ai

m对朋友

蛋糕一次做两个=>蛋糕数必须得是偶数(唯一限制条件) 

=>朋友对数只能是偶数

思路:

  1. m是偶数 就能全邀请 即不高兴值为0

  2. m是奇数 不邀请一个有奇数关系的人  不邀请一对朋友 使得 最后总对数为偶数

Code:

#include <bits/stdc++.h>

using namespace std;

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

const int N = 100010;

ll n, m, res;
ll a[N], b[N];
PII p[N];

void solve()
{
    memset(b, 0, sizeof(b));
    res = 1e9;
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    for (int i = 1; i <= m; i ++) cin >> p[i].first >> p[i].second;
    if (m % 2 == 0) 
    {
        cout << 0 << endl;
        return;
    }
    for (int i = 1; i <= m; i ++)
    {
        b[p[i].first] ++;
        b[p[i].second] ++;
    }
    for (int i = 1; i <= n; i ++)
        if (b[i] % 2 == 1) 
            res = min(res, a[i]);

    for (int i = 1; i <= m; i ++)
        res = min(res, a[p[i].first] + a[p[i].second]);

    cout << res << endl;

    return;
}
int main()
{
    int t;
    cin >> t;
    while (t --)
    {
        solve();
    }

    system("pause");

    return 0;
}

1711C 

题意:

给出一个矩形

行n 列m 颜色总数k 以及每种颜色使用次数ai .... ak

思路:

全部按行(列)染色 看看有没有机会染色成功

Code:

#include <bits/stdc++.h>

using namespace std;

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

const int N = 100010;

LL n, m, k;
LL a[N], b[N];
PII p[N];

void solve()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= k; i ++) cin >> a[i];

    sort(a + 1,a + 1+k);
    LL cols = 0, rows = 0;
    for (int i = 1; i <= k; i ++)
    {
        if (a[i] / n > 1) cols += a[i] / n;
        if (m - cols == 1) cols -= 2; // 若只剩一列 则要少染两列使得下次有机会全填满
        if (a[i] / m > 1) rows += a[i] / m;
        if (n - rows == 1) rows -= 2;
    }

    cout<< ((cols >= m || rows >= n) ? "Yes\\n" : "No\\n");
}
int main()
{
    int t;
    cin >> t;
    while (t --)
    {
        solve();
    }

    system("pause");

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值