Codeforces Round #660 (Div. 2)

A: Captain Flint and Crew Recruitment
思路:
用 6 10 14 15 去构造答案,因为只用前三个构造可能会出现重复的

参考代码:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
const ll maxn = 3e5 + 5;
//int a[maxn];
char s[N];
map<int, int> mp;
int pre[maxn], sum[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {

        int a = 6, b = 10, c = 14, d = 15;
        int n;
        cin >> n;
        if (n - a - b - c <= 0)
            cout << "NO" << endl;
        else
        {
            int e = n - a - b - c;
            if (e == a || e == b || e == c)
            {
                if (n - a - b - d <= 0)
                    cout << "NO" << endl;
                else
                {
                    cout << "YES" << endl;
                    cout << a << ' ' << b << ' ' << d << ' ' << n - a - b - d << endl;
                }
            }
            else
            {
                cout << "YES" << endl;
                cout << a << ' ' << b << ' ' << c << ' ' << e << endl;
            }
        }
    }
}

B:Captain Flint and a Long Voyage
思路:
他让用x构造最大的二进制串r,但这个x又要在所有可能里尽可能的小,这个x是个n位数,显然二进制串当然越长越好了,所以只有两种选择,9和8都是3位的,但又要让x尽可能的小,呢么删掉的n位就需要是8即可

参考代码:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
const ll maxn = 3e5 + 5;
//int a[maxn];
char s[N];
map<int, int> mp;
int pre[maxn], sum[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        string ans = string(n - (n + 3) / 4, '9') + string((n + 3) / 4, '8');
        cout << ans << endl;
    }
}

C:Uncle Bogdan and Country Happiness
给一颗树,树上的每个节点有一个点权和一开始有多少人,然后给出计算点权的方案,问这棵树的每个点权是否合法。
思路:
在这里插入图片描述

参考代码:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const ll N = 1e3 + 5;
const ll maxn = 3e5 + 5;
//ll a[maxn];
char s[N];
ll cnt;
map<ll, ll> mp;
ll pre[maxn], sum[maxn], head[maxn], w[maxn], nums[maxn];
ll good[maxn];
struct node
{
    ll v, nex;
} edge[maxn];
void add(ll u, ll v)
{
    edge[cnt].v = v, edge[cnt].nex = head[u];
    head[u] = cnt++;
}
bool fla;
void dfs(ll u, ll fa)
{
    pre[u] = fa;
    for (ll i = head[u]; ~i; i = edge[i].nex)
    {
        ll v = edge[i].v;
        if (v != fa)
            dfs(v, u), nums[u] += nums[v];
    }
    ll x = (nums[u] + w[u]) / 2, y;
    y = nums[u] - x;
    if (x < 0 || y < 0 || x + y != nums[u] || x - y != w[u])
        fla = false;
    good[u] = x;
    ll sum = 0;
    for (int i = head[u]; ~i; i = edge[i].nex)
        sum += good[edge[i].v];
    if (sum > good[u])
        fla = false;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t--)
    {
        memset(head, -1, sizeof head);
        ll n, m;
        cnt = 0;
        cin >> n >> m;
        for (ll i = 1; i <= n; i++)
            cin >> nums[i], good[i] = 0;
        for (ll i = 1; i <= n; i++)
            cin >> w[i];
        ll u, v;
        for (ll i = 1; i < n; i++)
            cin >> u >> v, add(u, v), add(v, u);
        fla = true;
        dfs(1, 0);
        if (fla)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值