Codeforces Round #296 (Div. 2) A B C D

简介:

A:模拟辗转相除法时记录答案

B:3种情况:能降低2,能降低1。不能降低分别考虑清楚

C:利用一个set和一个multiset,把行列分开考虑。利用set自带的排序和查询。每次把对应的块拿出来分成两块插入回去。然后行列分别取最大相乘的作为这次询问的答案

D:一个区间覆盖问题的变形。注意公式的话。非常easy发现事实上x。w相应的就是一个[x - w, x + w]的区间,然后求最多不重合区间就可以

代码:

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

typedef long long ll;

ll a, b, ans;

ll gcd(ll a, ll b) {
    if (!b) return a;
    ans += a / b;
    return gcd(b, a % b);
}

int main() {
    scanf("%lld%lld", &a, &b);
    gcd(a, b);
    printf("%lld\n", ans);
    return 0;
}

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

const int N = 200005;
int n;
char a[N], b[N];

int g[30][30];
int vis[30];

int main() {
    scanf("%d%s%s", &n, a + 1, b + 1);
    int sum = 0;
    for (int i = 1; i <= n; i++)
        if (a[i] != b[i]) sum++;
    for (int i = 1; i <= n; i++) {
        if (a[i] != b[i]) {
            if (g[b[i] - 'a'][a[i] - 'a']) {
                printf("%d\n%d %d\n", sum - 2, i, g[b[i] - 'a'][a[i] - 'a']);
                return 0;
            }
            g[a[i] - 'a'][b[i] - 'a'] = i;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (a[i] != b[i]) {
            vis[b[i] - 'a'] = i;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (a[i] != b[i] && vis[a[i] - 'a']) {
            printf("%d\n%d %d\n", sum - 1, i, vis[a[i] - 'a']);
            return 0;
        }
    }
    printf("%d\n-1 -1\n", sum);
    return 0;
}

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

int w, h, n;
set<int> x[2];
multiset<int> xx[2];
char op[2];
int v;
set<int>::iterator it, l, r;
multiset<int>::iterator tmp;

long long gao(int tp) {
    x[tp].insert(v);
    it = x[tp].find(v);
    l = it; l--; r = it; r++;
    xx[tp].erase(xx[tp].find(*r - *l));
    xx[tp].insert(v - *l);
    xx[tp].insert(*r - v);
    long long ans = 1;
    tmp = xx[tp].end(); tmp--;
    ans *= *tmp;
    tmp = xx[!tp].end(); tmp--;
    ans *= *tmp;
    return ans;
}

int main() {
    scanf("%d%d%d", &w, &h, &n);
    x[0].insert(0); x[0].insert(w);
    x[1].insert(0); x[1].insert(h);
    xx[0].insert(w); xx[1].insert(h);
    while (n--) {
        scanf("%s%d", op, &v);
        printf("%lld\n", gao(op[0] == 'H'));
    }
    return 0;
}

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

const int N = 200005;
const int INF = 0x3f3f3f3f;

struct Seg {
    int l, r;
    Seg() {}
    Seg(int l, int r) {
        this->l = l;
        this->r = r;
    }
} seg[N];

int n, x, w;

bool cmp(Seg a, Seg b) {
    return a.r < b.r;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &x, &w);
        seg[i] = Seg(x - w, x + w);
    }
    sort(seg, seg + n, cmp);
    int ans = 0;
    int r = -INF;
    for (int i = 0; i < n; i++) {
        if (seg[i].l >= r) {
            r = seg[i].r;
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}













本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5112806.html,如需转载请自行联系原作者

相关文章
|
5天前
|
人工智能 运维 安全
|
3天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
5天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
491 14
|
11天前
|
人工智能 JavaScript 测试技术
Qwen3-Coder入门教程|10分钟搞定安装配置
Qwen3-Coder 挑战赛简介:无论你是编程小白还是办公达人,都能通过本教程快速上手 Qwen-Code CLI,利用 AI 轻松实现代码编写、文档处理等任务。内容涵盖 API 配置、CLI 安装及多种实用案例,助你提升效率,体验智能编码的乐趣。
862 109
|
4天前
|
人工智能 测试技术 API
智能体(AI Agent)搭建全攻略:从概念到实践的终极指南
在人工智能浪潮中,智能体(AI Agent)正成为变革性技术。它们具备自主决策、环境感知、任务执行等能力,广泛应用于日常任务与商业流程。本文详解智能体概念、架构及七步搭建指南,助你打造专属智能体,迎接智能自动化新时代。