美文网首页
Codeforces 1359A - Berland Poker

Codeforces 1359A - Berland Poker

作者: 费城的二鹏 | 来源:发表于2020-06-02 19:45 被阅读0次

不知道这辈子有没有机会买套这样的房子,哈哈哈哈哈哈。

翻译

扑克游戏需要一副 n 张牌,有 m 个鬼牌,k 个玩家玩这个游戏。

游戏开始,每个玩家选 n/k 张牌。拿到最多的鬼牌数量的玩家获胜,他获得的分数为手中鬼牌数量的,和其他玩家手中最多鬼牌数量的差。如果两个人鬼牌数量一样多,两个人都获得零分。

输入格式

输入整数 t,表示测试用例组数。

每个测试用例输入 n m k,三个整数用空格分隔。

输出格式

输出最大分数。

分析

贪心算法,让获胜者尽量多拿鬼牌,然后其余玩家平分鬼牌,这样做减法即可。

代码(PyPy3)

# https://codeforces.com/problemset/problem/1359/A

import sys
import os
import heapq
import math

try:
    path = "./file/input.txt"
    if os.path.exists(path):
        sys.stdin = open(path, 'r')
    # sys.stdout = open(r"./file/output.txt", 'w')
except:
    pass

t = int(input())

def printd(value):
    # print(value)
    pass

for _ in range(t):
    arr = list(map(int, input().split(" ")))
    n, m, x, y = arr[0], arr[1], arr[2], arr[3]

    if x * 2 < y:
        y = x * 2
    
    result = 0
    for _ in range(n):
        row = input()
        i = 0
        while i < m:
            if row[i] == '*':
                i += 1
                continue
            else:
                if i < m - 1 and row[i + 1] == '.':
                    result += y
                    i += 2
                else:
                    result += x
                    i+= 1
    print(result)

更多代码尽在 https://github.com/Tconan99/Codeforces

by 费城的二鹏 2020.06.01 长春

相关文章

网友评论

      本文标题:Codeforces 1359A - Berland Poker

      本文链接:https://www.haomeiwen.com/subject/tldezhtx.html