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

來源:互聯網
上載者:User

標籤:

A:類比輾轉相除法時記錄答案

B:3種情況:能減少2,能減少1,不能減少分別考慮清楚

C:利用一個set和一個multiset,把行列分開考慮,利用set內建的排序和查詢,每次把相應的塊拿出來分成兩塊插入回去,然後行列分別取最大相乘的作為這次詢問的答案

D:一個區間覆蓋問題的變形,注意公式的話,很容易發現其實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;}


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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.