Loading

ak 日记 🍠

import sys
from cmath import *
line = sys.stdin.readline().strip()
vs = list(map(int, line.split()))
n, m, k = vs[0], vs[1], vs[2]
line = sys.stdin.readline().strip()
a = list(map(int, line.split()))
def solve(n, m, k, a):
    tmp = k/n
    #镜像t次
    t = int(tmp)
    if t < tmp:
        t+=1
        if t%2:
            return a[k%n-1]
        else:
            return a[::-1][k%n-1]
    else:
        if t%2==0:
            return a[-1]
        else:
            return a[::-1][-1]

# n, m, k = 3, 3, 10
# a= [1, 2, 3]
print(solve(n,m,k,a))
import collections
import sys
from cmath import *
n = int(sys.stdin.readline().strip())
line = sys.stdin.readline().strip()
a = list(map(int, line.split()))
def solve(a, n):
    counter = collections.Counter(a)
    counter = dict(sorted(counter.items(), key=lambda kv: kv[0], reverse=True))
    keys = list(counter.keys())
    flag = 1
    if abs(keys[0] - 7) <= abs(keys[-1] + 7):
        if 7 not in counter:
            counter[7] = 1
        else:counter[7] += 1  # 保证有7
        counter[keys[0]] -= 1
        ans = abs(keys[0] - 7)
        flag = 1
    else:
        if -7 not in counter:
            counter[-7] = 1
        else:counter[-7] += 1  # 保证有-7
        counter[keys[-1]] -= 1
        ans = abs(keys[-1] + 7)
        flag = 0
    if flag:seven = 7
    else:seven = -7
    if 1 not in counter:counter[1] = 0
    if -1 not in counter:counter[-1] = 0
    counter = dict(sorted(counter.items(), key=lambda kv: kv[0], reverse=True))
    for key in counter.keys():
        # print(key, counter)
        if counter[key] <= 0 or (key==seven and counter[key]==1):
            # counter.__delitem__(key)
            continue
        if key == seven and counter[key] > 1:
            ans += (counter[key] - 1) * 6
            counter[1] += counter[key] - 1
        elif key != 1 and key != -1:
            if abs(key - 1) <= abs(key + 1):
                counter[1] += counter[key]
                ans += counter[key] * abs(key - 1)
                counter[key] = 0
            else:
                counter[-1] += counter[key]
                ans += counter[key] * abs(key + 1)
                counter[key] = 0
            # counter.__delitem__(key)

    if -1 in counter and counter[-1] % 2 == flag:
        counter[-1] -= 1
        counter[1] += 1
        ans += 2
    # print(counter)
    return ans
# n = 5
# a = [-6,0,2,-2,3]
res = solve(a, n)
print(res)
import sys
from cmath import *
import collections

line = sys.stdin.readline().strip()
vs = list(map(int, line.split()))
n, m, k = vs[0], vs[1], vs[2]
line = sys.stdin.readline().strip()
u = list(map(int, line.split()))
line = sys.stdin.readline().strip()
v = list(map(int, line.split()))
line = sys.stdin.readline().strip()
w = list(map(int, line.split()))
from functools import lru_cache

class Solution:
    ans = inf

    def solve(self, n, m, k, u, v, w):
        g = collections.defaultdict(set)
        for i in range(len(u)):
            g[u[i]].add((v[i], w[i]))
            g[v[i]].add((u[i], w[i]))

        @lru_cache(None)
        def dfs(u=1, minw=0, paths=0):
            if u == n and paths <= k:
                self.ans = min(self.ans, minw)
            if u < n and paths < k:
                for v, w in g[u]:
                    dfs(v, max(w, minw), paths + 1)

        self.ans = inf
        dfs()
        return self.ans

sol = Solution()
res = sol.solve(n, m, k, u, v, w)
print(res)

 

posted @ 2022-09-04 18:01  ArkiWang  阅读(64)  评论(0编辑  收藏  举报