AtCoder ABC201

文章介绍了四个编程挑战题目,涉及C-SecretNumber的简单遍历、D-GameinMomotetsuWorld的动态规划策略、E-XorDistances利用异或性质的解法,以及F-InsertionSort中的优化DP和数据结构运用。

本期很有难度,D E F都不是一眼能看出的题目

C - Secret Number

遍历0-10000的数字即可

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @file     : atcoder.py
# @software : PyCharm

import bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(100010)


def main():
    items = sys.version.split()
    fp = open("in.txt") if items[0] == "3.10.6" else sys.stdin
    ans = 0
    ss = fp.readline().strip()
    for i in range(10000):
        t = i
        s = set()
        for j in range(4):
            s.add(t % 10)
            t //= 10

        flag = 1
        for j in range(10):
            if ss[j] == 'o':
                if j not in s:
                    flag = 0
            elif ss[j] == 'x':
                if j in s:
                    flag = 0
        ans += flag
    print(ans)


if __name__ == "__main__":
    main()

D - Game in Momotetsu World

想了几个dp的方案都不是很好
比较好的方法是:
f ( i , j ) f(i,j) f(i,j)为从 ( i , j ) (i,j) (i,j)点出发的T分数-A分数差的最优解
对于T来说,要使这个解最大
对于A来说,要使这个解最小
注意A在某步达到+,那么该步对于最优解的贡献score是-2
转移很简单,见题解

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <unordered_map>
#include <algorithm>
#define LT(x) (x * 2)
#define RT(x) (x * 2 + 1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

int n, m;
char w[2020][2020];

int mem[2020][2020];

int get(int r, int c, int turn) {
   
   
    if (mem[r][c] != -1) {
   
   
        return mem[r][c];
    }
    int& res = mem[r][c];
    int nr, nc;
    if (turn == 0) {
   
   
        res = -(1 << 28);
        nr = r + 1, nc = c;
        if (nr < n && nc < m) {
   
   
            res = max(res, get(nr, nc, 1) + (w[nr][nc] == '+' ? 2 : -2));
        }
        nr = r, nc = c + 1;
        if (nr < n && nc < m) {
   
   
            res = max(res, get(nr, nc, 1) + (w[nr][nc] == '+' ? 2 : -2));
        }
    }
    else {
   
   
        res = 1 << 28;
        nr = r + 1, nc = c;
        if (nr < n && nc < m) {
   
   
            res = min(res, get(nr, nc, 0) + (w[nr][nc] == '+' ? -2 : 2));
        }
        nr = r, nc = c + 1;
        if (nr < n && nc < m) {
   
   
            res = min(res, get(nr, nc, 0) + (w[nr][nc] == '+' ? -2 : 2));
        }
    }
    return res;
}


int main() {
   
   
    //freopen("in.txt", "r", stdin);
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) {
   
   
        scanf("%s", w[i]);
    }
    
    memset(mem, 0xff, sizeof(mem));
    mem[n - 1][m - 1] = 0;
    int ans = get(0, 0, 0);
    if (ans > 0) {
   
   
        printf("Takahashi\n");
    }
    else if (ans < 0) {
   
   
        printf
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值