codeforces round 886 div4

A To My Critics

问题:

思路:找到a + b  a + c c + b中的最小值并判断是否大于10

#include <iostream>

using namespace std;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    int minv = min(a, min(b, c));
    if(a + b + c - minv >= 10) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

B Ten Words Of Wisdom

问题:

思路:找到长度不超过10的质量最大值对应人的编号

代码:
带权并查集 差分约束待补....

#include <iostream>

using namespace std;

const int N = 55;

int a[N], b[N];

void solve() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++ ) cin >> a[i] >> b[i];
    
    int ans = 0;
    int now = 0;

    for(int i = 1; i <= n; i ++ ) {
        if(a[i] <= 10) {
            if(b[i] > now) {
                now = b[i];
                ans = i;
            }
        }
    }

    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;

    while(t -- ) {
        solve();
    }
    return 0;
}

C Word on Paper

问题:

思路:按照读入顺序输出

代码:

#include <iostream>
#include <vector>

using namespace std;

const int N = 10;

void solve() {
    vector<char> ans;

    for(int i = 1; i <= 8; i ++ ) {
        for(int j = 1; j <= 8; j ++ ) {
            char c;
            cin >> c;
            if(c != '.')
                ans.push_back(c);
        }
    }

    for(auto t: ans) cout << t;
    cout << endl;
}

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

D Balanced Round

问题:

思路:排序后用n减去最长的平衡的一段

代码:

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 2e5 + 10;

int a[N];
int n, k;

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

    int cnt = 0;
    int res = 0;

    for(int i = 1; i <= n - 1; i ++ ) {
        cnt ++;
        if(a[i + 1] - a[i] > k) {
            res = max(res, cnt);
            cnt = 0;
        }
    }

    cnt ++;
    res = max(res, cnt);

    cout << n - res << endl;
}

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

E:Cardboard of Pictures

问题:

思路:二分答案,可能会爆long long记得开unsigned long long

代码:

#include <iostream>

using namespace std;

const int N = 2e5 + 10;

int s[N];
int n;
long long c;

bool check(long long mid) {
    unsigned long long sum = 0;
    for(int i = 1; i <= n; i ++ ) {
        sum += ((unsigned long long)s[i] + mid + mid) * (s[i] + mid + mid);
        if(sum > c) return false;
    }
    return true;
}

void solve() {
    cin >> n >> c;

    for(int i = 1; i <= n; i ++ ) cin >> s[i];

    long long l = 1, r = 1e9;
    while(l < r) {
        long long mid = (l + r + 1) / 2;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l << endl;
}

int main() {
    int t;
    cin >> t;

    while(t -- ) {
        solve();
    }
    return 0;
}

问题:二分条件为sum <= c的代码仍然wa中...

F We Were Both Children

问题:

思路:找到每个点的约数并判断该约数是否可以达到

代码:

#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int N = 2e5 + 10;

int n;
int a[N], cnt[N];

void solve() {
    memset(cnt, 0, sizeof cnt);
    cin >> n;
    
    for(int i = 1; i <= n; i ++ ) {
        int x;
        cin >> x;
        if(x <= n) cnt[x] ++;
    }     

    int ans = 0;
    for(int i = 1; i <= n; i ++ ) {
        int res = 0;
        for(int j = 1; j * j <= i; j ++ ) {
            if(i % j == 0) {
                res += cnt[j];
                if(i / j != j) res += cnt[i / j];
            }
        }
        ans = max(res, ans);
    }
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;

    while(t -- ) {
        solve();
    }
    return 0;
}

G:The Morning Star

问题:

思路:用map预处理
代码:

​
​
#include <iostream>
#include <map>
#include <cmath>

using namespace std;

const int N =  2e5 + 10;
const int INF = 2e9;

typedef pair<int, int> PII;
PII a[N];
int n;

void solve() {
    map<int, int> mx;
    map<int, int> my;
    map<int, int> k1;
    map<int, int> k2;

    cin >> n;
    for(int i = 1; i <= n; i ++ ) {
        int x, y;
        cin >> x >> y;
        a[i] = {x, y};
        mx[x] ++;
        my[y] ++;
        k1[x - y + INF] ++;
        k2[x + y + INF] ++;
    }

    long long ans = 0;
    for(int i = 1; i <= n; i ++ ) {
        ans += mx[a[i].first] - 1;
        ans += my[a[i].second] - 1;
        ans += k1[a[i].first - a[i].second + INF] - 1;
        ans += k2[a[i].first + a[i].second + INF] - 1;
    }
    cout << ans << endl;
}

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

​

​

H:The Third Letter

问题:

思路:如果两个点有关系就在这两个点之间加一条无向边,最后再bfs扫图,判断是否存在冲突条件

problem:最开始处理的时候并没有考虑到最后建起的图可能不是连通的,也正因为可能存在多个图,边必须要加成无向边

代码:

#include <iostream>
#include <vector>
#include <cstring>
#include <queue>

using namespace std;

const int N = 2e5 + 10;
const long long INF = 1e18;

int h[N], val[N << 1], ne[N << 1], w[N << 1], idx;
int n, m;

void add(int a, int b, int c) {
    val[idx] = b;
    ne[idx] = h[a];
    w[idx] = c;
    h[a] = idx ++;
}

void solve() {
    memset(h, -1, sizeof h);
    idx = 0;
    cin >> n >> m;
    vector<long long> pos(n + 1, INF);

    while(m -- ) {
        int a, b, d;
        cin >> a >> b >> d;
        add(a, b, d);
        add(b, a, -d);
    }
    
    bool flag = true;
    for(int i = 1; i <= n; i ++ ) {
        if(pos[i] == INF) {
            pos[i] = 0;
            queue<int> q;
            q.push(i);
            while(q.size()) {
                int t = q.front();
                q.pop();
                for(int i = h[t]; i != -1; i = ne[i]) {
                    int j = val[i];
                    if(pos[j] == INF) {
                        pos[j] = pos[t] + w[i];
                        q.push(j);
                    } else {
                        if(pos[j] != pos[t] + w[i]) {
                            flag = false;
                            break;
                        }
                    }
                }
            }
        }
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    int t;
    cin >> t;

    while(t -- ) {
        solve();
    }
    return 0;
}
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值