Codeforces Round #230 (Div. 2)

Problems
 
 
# Name    
A
Nineteen
standard input/output
1 s, 256 MB
   x1710
B
Three matrices
standard input/output
1 s, 256 MB
   x1806
C
Blocked Points
standard input/output
2 s, 256 MB
   x418
D
Tower of Hanoi
standard input/output
1 s, 256 MB
   x147
E
Yet Another Number Sequence
standard input/output
1 s, 256 MB
   x12
A题:统计每个字符的个数,然后n的个数先-1,因为开头第一个nineteen是需要3个n的,然后n/2和i/1和t/1和e/2的最小值就是答案,或者直接模拟一个个去减掉也可以。
B题: 根据题目公式可以推出Wij = aij + bij; Wji = aji + bji = aij - bij; 所以aij = (Wij + Wji) / 2, bij = (Wij - Wji) / 2。
C题:听说可以找规律,但是其实O(n)也能过,枚举x轴,然后算出y轴上最靠近圆周的整数的y坐标,然后前一个的y坐标-后一个的y坐标中间这一段都是要阻断的点,注意如果前后y坐标相同,也是要减去一个的。
D题:汉诺塔问题的变形,注意状态有2种转移方式即可。
E题:应该是矩阵快速幂,暂时没什么想法
代码:
A:
#include 
#include 

char str[105];
int num[26];
int main() {
    scanf("%s", str);
    for (int i = 0; i < strlen(str); i++) {
        num[str[i] - 'a']++;
    }
    int ans = 0; num['n' - 'a']--;
    while (num['n' - 'a'] >= 2 && num['e' - 'a'] >= 3 && num['t' - 'a'] >= 1 && num['i' - 'a'] >= 1) {
        num['n' - 'a'] -= 2; num['e' - 'a'] -= 3; num['t' - 'a'] -= 1; num['i' - 'a'] -= 1;
        ans++;
    }
    printf("%d\n", ans);
    return 0;
}
B:
#include 
#include 

const int N = 175;
int n;
double w[N][N], a[N][N], b[N][N];

int main() {
    int i, j;
    scanf("%d", &n);
    for (i = 0; i< n; i++)
        for (j = 0; j < n; j++)
            scanf("%lf", &w[i][j]);
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++) {
            a[i][j] = (w[i][j] + w[j][i]) / 2;
            b[i][j] = (w[i][j] - w[j][i]) / 2;
        }
    for (i = 0; i < n; i++) {
        for (j = 0; j < n - 1; j++) {
            printf("%.8lf ", a[i][j]);
        }
        printf("%.8lf\n", a[i][j]);
    }
    for (i = 0; i < n; i++) {
        for (j = 0; j < n - 1; j++) {
            printf("%.8lf ", b[i][j]);
        }
        printf("%.8lf\n", b[i][j]);
    }
    return 0;
}

C题:
#include 
#include 
#include 

int main () {
    __int64 n, ans = 0;
    scanf("%I64d", &n);
    double R = n;
    __int64 tmp = n;
    for (int i = 1; i <= n; i++) {
        double r = i;
        __int64 k = sqrt(R*R - r*r);
        if (tmp - k == 0)
            ans += 1;
        else
            ans += tmp - k;
        tmp = k;
    }
    if (n == 0) printf("1\n");
    else printf("%I64d\n", ans * 4);
    return 0;
}

D题:
#include 
#include 
#define INF 0x3f3f3f3f3f3f3f
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

__int64 dp[45][3][3];
int n;

__int64 solve() {
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                dp[i][j][k] = min(dp[i][j][k], min(dp[i - 1][j][3 - j - k], dp[i - 1][j][k] + dp[i - 1][k][3 - j - k]) + dp[1][j][k] + min(dp[i - 1][3 - j - k][k], dp[i - 1][3 - j - k][j] + dp[i - 1][j][k]));
                dp[i][j][k] = min(dp[i][j][k], min(dp[i - 1][j][k], dp[i - 1][j][3 - j - k] + dp[i - 1][3 - j - k][k]) + dp[1][j][3 - j - k] + min(dp[i - 1][k][j], dp[i - 1][k][3 - j - k] + dp[i - 1][3 - j - k][j]) + dp[1][3 - j - k][k] + min(dp[i - 1][j][k], dp[i - 1][j][3 - j - k] + dp[i - 1][3 - j - k][k]));
            }
        }
    }
    if (n == 1) dp[n][0][2] = min(dp[n][0][2], dp[n][0][1] + dp[n][1][2]);
    return dp[n][0][2];
}

int main() {
    int i, j, k;
    for (i = 0; i <= 40; i++)
        for (j = 0; j < 3; j++)
            for (k = 0; k < 3; k++) {
                dp[i][j][k] = INF;
            }
    for (i = 0; i < 3; i++)
        for (j = 0; j < 3; j++)
            scanf("%I64d", &dp[1][i][j]);
    scanf("%d", &n);    
    printf("%I64d\n", solve());
    return 0;
}


你可能感兴趣的:(Codeforces Round #230 (Div. 2))