Codeforces Round #228 (Div. 2)

Problems
Codeforces Round #228 (Div. 2)
 
 
# Name    
A
standard input/output
1 s, 256 MB
Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) x2033
B
standard input/output
1 s, 256 MB
Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) x1738
C
standard input/output
1 s, 256 MB
Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) x1076
D
standard input/output
1 s, 256 MB
Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) x68
E
standard input/output
1 s, 256 MB
Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) Codeforces Round #228 (Div. 2) x120


A:其实看样例就能看出是求最小公约数*n即可了。因为所有数字减到最后肯定剩下最小公约数。


B:十字架一个个去放,放慢即可。


C:贪心,开始题意都理解错了,还好友大神的鼎力相助(ORZ),理解成第i个上面不能放重量超过Xi,其实是个数不能超过Xi,这样一来就简单了,直接从小箱子从顶部开始放去模拟即可


D:构造问题,给出k,要构造k条路径,先构造两部分路径,如下图,这样一来只要选①的点和②的点去连,路径数就是i * 1 +i * 2 + i * 4 + i * 8 + i * 16....(i = 1或 0) 就能构造出k条路径。

Codeforces Round #228 (Div. 2)Codeforces Round #228 (Div. 2)

Codeforces Round #228 (Div. 2)

E:贪心,当时5分钟想5分钟敲出来,居然还1发过了,可惜FST了。排序的地方写错了,

大概思路是:贪心,两个人都想用最好的方法去取,那么对于一堆扑克,如果是偶数,肯定是对半拿,奇数肯定有一个人多拿一个,如果有多堆奇数,那么肯定有一半是一个人拿多一个。因为两个人都想拿最优,肯定不会又人占到便宜,最后肯定是一半一半了。问题就在奇数堆上,奇数堆中间那项,肯定是从大到小交替拿的,那只要按中间项排序即可。

代码:

A:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int n, num[105], i;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &num[i]);
    }
    int t = num[0];
    for (i = 1; i < n; i++) {
        t = gcd(t, num[i]);
    }
    printf("%d\n", t * n);
    return 0;
}


B:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int N = 105;
const int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n, vis[N][N], ans;
char g[N][N];


bool ju(int x, int y) {
    if (x < 0 || x >= n || y < 0 || y >= n) return false;
    if (g[x][y] == ‘.‘) return false;
    for (int i = 0; i < 4; i++) {
        int xx = x + d[i][0];
        int yy = y + d[i][1];
        if (xx < 0 || xx >= n || yy < 0 || yy >= n) return false;
        if (g[xx][yy] == ‘.‘ || vis[xx][yy]) return false;
    }
    return true;
}

bool solve() {
    int num = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            if (ju(i, j)) {
                vis[i][j] = 1;
                num++;
                for (int k = 0; k < 4; k++) {
                    int xx = i + d[k][0];
                    int yy = j + d[k][1];
                    vis[xx][yy] = 1;
                    num++;
                }
            }   
        }
    if (num == ans)
        return true;
    return false;
}

int main() {
    ans = 0;
    memset(vis, 0, sizeof(vis));
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", g[i]);
        for (int j = 0; j < n; j++)
            if (g[i][j] == ‘#‘) ans++;
    }
    printf("%s\n", solve() ? "YES" : "NO");
    return 0;
}

C:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))

int n, x[105], i, j, ans = 0, blo[105];

int find(int xx) {
    for (int i = 0; i < ans; i++)
        if (xx >= blo[i])
            return i;
    return ans++;
}

int main() {
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &x[i]);
    sort(x, x + n);
    for (i = 0; i < n; i++) {
        blo[find(x[i])]++;
    }
    printf("%d\n", ans);
    return 0;
}

D:

#include <stdio.h>
#include <string.h>

const int N = 1005;
int k, g[N][N], i, j;

void make(int now1, int now2, int to1, int to2) {
    g[now1][to1] = g[now1][to2] = g[now2][to1] = g[now2][to2] = 1;
}

int main() {
    scanf("%d", &k);
    g[1][3] = g[3][4] = g[3][5] = 1;
    int now1 = 4, now2 = 5, to1 = 6, to2 = 7;
    while (to2 < 90) {
        make(now1, now2, to1, to2);
        now1 += 2; now2 += 2; to1 += 2; to2 += 2;
    }
    for (i = 100; i < 200; i++)
        g[i][i + 1] = 1;
    g[200][2] = 1;
    for (i = 0; i < 32; i++) {
        if (k&(1<<i)) {
            g[(i + 2) * 2][i + 100] = 1;
        }
    }
    printf("200\n");
    for (i = 1; i <= 200; i++) {
        for (j = 1; j <= 200; j++) {
            if (g[i][j] || g[j][i]) printf("Y");
            else printf("N");
        }
        printf("\n");
    }
    return 0;
}

E:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int N = 105;
int n, i, j;

struct Pipe {
    int s[N], top, bottom, sum;
} p[N];

bool cmp(Pipe a, Pipe b) {
    return a.sum > b.sum;
}

int main() {
    memset(p, 0, sizeof(p));
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &p[i].bottom);
        for (j = 0; j < p[i].bottom; j++) {
            scanf("%d", &p[i].s[j]);
            p[i].sum = p[i].s[p[i].bottom / 2];
        }
    }
    sort(p, p + n, cmp);
    int ans1 = 0, ans2 = 0, bo = 0;
    for (i = 0; i < n; i++) {
        if (p[i].bottom % 2== 0) {
            for (j = 0; j < p[i].bottom / 2; j++) {
                ans1 += p[i].s[j];
            }
            for (; j< p[i].bottom;j++)
                ans2 += p[i].s[j];
        }
        else {
        for (j = 0; j < p[i].bottom / 2 + (bo % 2 == 0); j++)
            ans1 += p[i].s[j];
        for (;j < p[i].bottom; j++)
            ans2 += p[i].s[j];
        bo++;
        }
    }
    printf("%d %d\n", ans1, ans2);
    return 0;
}


Codeforces Round #228 (Div. 2)

上一篇:链表剖析之单链表剖析(二)


下一篇:HDU 2047 阿牛的EOF牛肉串.