yukicoder contest 252 Participation record

yukicoder contest 252 Participation record

A 1076 Sushi hitting

Since the Monte Carlo method was useless, I did the mathematics seriously. If the expected value to be obtained is n, then n = p * (1 + n) + (1 --p) * 0, so n = p / (1 --p) Will be.

p = float(input())

print(p / (1 - p))

B 1077 Noel and the stars 4

If you search for "Broadly-sense monotonous increase competition pro", the code for POJ-3666: Making the Grade will appear, so you can comment out and post the code on the broad-sense monotonous decrease column side (cruel).

Addendum: Solved properly. When Y i-1 </ sub> after movement is x, if the sum of the distances moved up to that point is dp [i -1] [x], then dp [i ] [x] is min (dp [i -1] [0], dp [i -1] [1], ..., dp [i -1] [x]) + abs (Y i < / sub> --x).

N = int(input())
Y = list(map(int, input().split()))

dp = [[0] * (10 ** 4 + 1) for _ in range(N)]

for i in range(N):
    t = float('inf')
    for j in range(10 ** 4 + 1):
        t = min(t, dp[i - 1][j])
        dp[i][j] = t + abs(Y[i] - j)

print(min(dp[N - 1]))

In Python, it becomes TLE and can only be passed in PyPy. By the way, although it is written in 2D, it actually works in 1D because there is no overlap. Also, the destination of Y i </ sub> There is no problem with the coordinates of Y 1 </ sub>, ..., Y N </ sub>. If you write with the above in mind, the code will pass even in Python. ..

N = int(input())
Y = list(map(int, input().split()))

a = sorted(set(Y))
dp = [0] * len(a)

for i in range(N):
    t = float('inf')
    for j in range(len(a)):
        t = min(t, dp[j])
        dp[j] = t + abs(Y[i] - a[j])

print(min(dp))

Recommended Posts

yukicoder contest 265 Participation record
yukicoder contest 266 Participation record
yukicoder contest 263 Participation record
yukicoder contest 243 Participation record
yukicoder contest 273 Participation record
yukicoder contest 252 Participation record
yukicoder contest 259 Participation record
yukicoder contest 249 Participation record
yukicoder contest 271 Participation record
yukicoder contest 251 Participation record
yukicoder contest 242 Participation record
yukicoder contest 241 Participation record
yukicoder contest 277 Participation record
yukicoder contest 257 Participation record
yukicoder contest 254 Participation record
yukicoder contest 246 Participation record
yukicoder contest 275 Participation record
yukicoder contest 274 Participation record
yukicoder contest 247 Participation record
yukicoder contest 261 Participation record
yukicoder contest 278 Participation record
yukicoder contest 248 Participation record
yukicoder contest 270 (mathematics contest) Participation record
yukicoder contest 272 (Weird math contest) Participation record
yukicoder contest 256 entry record
yukicoder contest 267 entry record
yukicoder contest 264 entry record
yukicoder contest 245 entry record
yukicoder contest 250 entry record
yukicoder contest 262 entry record
yukicoder contest 264 Review
yukicoder contest 261 Review
yukicoder contest 267 Review
yukicoder contest 266 Review
yukicoder contest 263 Review
yukicoder contest 268 Review
AtCoder Beginner Contest 181 Participation Report
AtCoder Beginner Contest 161 Participation Report
AtCoder Beginner Contest 176 Participation Report
AtCoder Beginner Contest 154 Participation Report
AtCoder Beginner Contest # 003 Participation Note
AtCoder Grand Contest 041 Participation Report
AtCoder Beginner Contest 166 Participation Report
AtCoder Grand Contest 040 Participation Report
AtCoder Beginner Contest 153 Participation Report
AtCoder Beginner Contest 145 Participation Report
AtCoder Beginner Contest 184 Participation Report
AtCoder Beginner Contest 165 Participation Report
AtCoder Beginner Contest 160 Participation Report
AtCoder Beginner Contest 169 Participation Report
AtCoder Beginner Contest 178 Participation Report
AtCoder Beginner Contest 163 Participation Report
AtCoder Beginner Contest 159 Participation Report
AtCoder Beginner Contest 164 Participation Report
AtCoder Regular Contest 105 Participation Report
AtCoder Beginner Contest 168 Participation Report
AtCoder Beginner Contest 150 Participation Report
AtCoder Beginner Contest 158 Participation Report
AtCoder Beginner Contest 180 Participation Report
AtCoder Regular Contest 104 Participation Report
AtCoder Beginner Contest 156 Participation Report