1. 程式人生 > >Coder-Strike 2014 - Round 2

Coder-Strike 2014 - Round 2

個人 min || als 表示 algo space else printf

t題目鏈接:Coder-Strike 2014 - Round 2

A題:簡單水題,註意能加入反復的數字。因此僅僅要推斷是否能把Min和Max加入好。就能夠了

B題:開一個sum計算每一個聊天總和,和一個s計算每一個人在每一個聊天總和,最後每一個人就用總和減掉自己發送的就可以

C題:最優策略為先把非特殊的答完,然後從最大的開始答

D題:dp,狀態為dp[i][j][k],i表示當前長度,j表示前面數字的總和,k表示是否能組成,然後進行記憶化搜索

代碼:

A:

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

int n, m, Min, Max, num[105];

bool judge() {
    int f1 = 0, f2 = 0;
    for (int i = 0; i < m; i++) {
	if (num[i] < Min || num[i] > Max)
	    return false;
	if (num[i] == Min) f1--;
	if (num[i] == Max) f2--;
    }
    int yu = n - m;
    if (!f1) yu--;
    if (!f2) yu--;
    if (yu < 0) return false;
    return true;
}

int main() {
    scanf("%d%d%d%d", &n, &m, &Min, &Max);
    for (int i = 0; i < m; i++)
	scanf("%d", &num[i]);
    if (judge()) printf("Correct\n");
    else printf("Incorrect\n");
    return 0;
}

B:

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

const int N = 20005;

int n, m, k, vis[N][15], sum[15], s[N][15], ans[N];

int main() {
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
        scanf("%d", &vis[i][j]);
    }
    int x, y;
    while (k--) {
    scanf("%d%d", &x, &y);
    x--; y--;
    sum[y]++;
    s[x][y]++;
    }
    for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
        if (vis[i][j])
        ans[i] += (sum[j] - s[i][j]);
    }
    }
    for (int i = 0; i < n - 1; i++)
    printf("%d ", ans[i]);
    printf("%d\n", ans[n - 1]);
    return 0;
}

C:

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

const int N = 10000005;
int n, m;
long long sum, Max, vis[N];
struct Num {
    long long num;
    int vis;
} num[N];

bool cmp(Num a, Num b) {
    return a.num > b.num;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
    scanf("%lld", &num[i].num);
    sum += num[i].num;
    Max = max(Max, num[i].num);
    }
    int v;
    for (int i = 0; i < m; i++) {
    scanf("%d", &v);
    sum -= num[v - 1].num;
    num[v - 1].vis = 1;
    }
    sort(num, num + n, cmp);
    for (int i = 0; i < n; i++) {
    if (num[i].vis) {
        if (sum >= num[i].num)
        break;
        sum += num[i].num;
        m--;
    }
    }
    for (int i = 0; i < m; i++)
    sum *= 2;
    printf("%lld\n", sum);
    return 0;
}

D:

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

const int MOD = 1000000007;
const int N = 2005;
const int M = 8050;
int n, k, num[N], dp[N][M][2], vis[N][M][2];

int solve(int len, int s, int flag) {
    if (s>=(1<<k)) flag = 1;
    if (vis[len][s][flag])
        return dp[len][s][flag];
    vis[len][s][flag] = 1;
    dp[len][s][flag] = 0;
    if (len == n) {
        return dp[len][s][flag] = flag;
    }
    if (num[len] == 0) {
        dp[len][s][flag] = (dp[len][s][flag] + solve(len + 1, s + 2, flag)) % MOD;
        if ((s&(1<<1)) == 0) {
            dp[len][s][flag] = (dp[len][s][flag] + solve(len + 1, s + 4, flag)) % MOD;
        }
        else {
            dp[len][s][flag] = (dp[len][s][flag] + solve(len + 1, 4, flag)) % MOD;
        }
    }
    else {
        if (num[len] == 2)
            dp[len][s][flag] = (dp[len][s][flag] + solve(len + 1, s + num[len], flag)) % MOD;
        else {
            if ((s&(1<<1)) == 0) {
                dp[len][s][flag] = (dp[len][s][flag] + solve(len + 1, s + num[len], flag)) % MOD;
            }
            else {
                dp[len][s][flag] = (dp[len][s][flag] + solve(len + 1, num[len], flag)) % MOD;
            }
        }
    }
    return dp[len][s][flag];
}

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


Coder-Strike 2014 - Round 2