Codeforces Round #186 (Div. 2)A、B、C、D、E

來源:互聯網
上載者:User

A.Ilya and Bank Account

Ilya得到了一個禮物,可以在刪掉銀行賬戶最後和倒數第二位的數字(賬戶有可能是負的),也可以不做任何處理。

//codeforces 313A //2013-05-31-13.47#include <stdio.h>#include <algorithm>using namespace std;int main(){    int n;    scanf("%d", &n);    if (n)    {        if (n >= 0)        {            printf("%d\n", n);        }        else        {            n = -n;            int a = n/10;            int b = n/100 * 10 + n%10;            printf("%d\n", -min(a, b));        }    }    return 0;}

B.Ilya and Queries

給你一個字串,然後有M個詢問,尋問的是從l到r之間有多少對字串滿足 s[i] == s[i+1]。

簡單的樹狀數組題目

//codeforces 313 B//2013-05-31-14.15#include <stdio.h>#include <string.h>const int maxn = 100005;char s[maxn];int a[maxn];int n;inline int lowbit(int x){    return x&-x;}void update(int x){    while (x <= n)    {        a[x] += 1;        x += lowbit(x);    }}int getsum(int x){    int sum = 0;    while (x)    {        sum += a[x];        x -= lowbit(x);    }    return sum;}int main(){    while (scanf("%s", s) != EOF)    {        int m, l, r;        n = strlen(s);        memset(a, 0, sizeof(a));        for (int i = 0; i < n-1; i++)        {            if (s[i] == s[i+1])                update(i+1);        }        scanf("%d", &m);        while (m--)        {            scanf("%d %d", &l, &r);            printf("%d\n", getsum(r-1) - getsum(l-1));        }    }    return 0;}

C.Ilya and Matrix

給你4^n個數,讓你放進那個2^n * 2^n的矩陣裡讓這個矩陣beauty值最大,beauty值的計算方法題裡說了。。。

The beauty of a 2n × 2n-sized matrix is an integer, obtained by the following algorithm:


Find the maximum element in the matrix. Let's denote it as m.
If n = 0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2n - 1 × 2n - 1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices.

As you can see, the algorithm is recursive

貪心吧,貪心就行,排個序解決了

//codeforces 313c//2013-06-03-15.55#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 2*1000006;__int64 a[maxn];bool cmp(int x, int y){    return x > y;}int main(){    int n;    while (scanf("%d", &n) != EOF)    {        for (int i = 1; i <= n; i++)            scanf("%I64d", &a[i]);        sort(a+1, a+n+1, cmp);        int x = n;        __int64 ans = 0;        while (x)        {            for (int i = 1; i <= x; i++)                ans += a[i];            x /= 4;        }        printf("%I64d\n", ans);    }    return 0;}

D.Ilya and Roads

E.Ilya and Two Numbers

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.