0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ABC224 チャレンジ結果

Posted at

ABC224結果:AB2完
Cが終了後数分でACに持っていけたため非常に悔しい思い...
図形問題苦手です.

A:文字列の末尾で場合分け

Tires.py
S = input()
if S[-1] == "r":
    print("er")
if S[-1] == "t":
    print("ist")

B:for文の途中終了の仕方イケてない, 冗長やし他にやり方ないものか.

Mongeness.py
H, W = list(map(int, input().split()))
A_list = []
for i in range(H):
    X = list(map(int, input().split()))
    A_list.append(X)

flag = True
for i1 in range(H):
    X = 0
    for i2 in range(i1+1, H):
        Y = 0
        for j1 in range(W):
            Z = 0
            for j2 in range(j1+1, W):
                if A_list[i1][j1] + A_list[i2][j2] > A_list[i2][j1] + A_list[i1][j2]:
                    flag = False
                    print("No")
                    X += 1
                    Y += 1
                    Z += 1
                    break
            if Z == 1:
                break
        if Y == 1:
            break
    if X == 1:
        break

if flag == True:
    print("Yes")

C:三角形にならない三点とは?→三点が一直線上にある→傾きが一致するか判定すればいい!
ここまではよかったが, 精度の関係上非常に直線に近い三角形を直線判定してしまい時間内にACできず. 傾きではなく比で比較するとACできた.
なお傾き比較でもlong double型を使えばできるようです(未確認).

Triangle?.py
import math

N = int(input())
ten = []
for i in range(N):
    Z = tuple(map(int, input().split()))
    ten.append(Z)

num = 0
for i in range(N-1):
    A = []
    b = 0
    for j in range(i+1, N):
        x = ten[i][0] - ten[j][0]
        y = ten[i][1] - ten[j][1]
        if x != 0:
            k = math.gcd(x, y)
            x1 = x // k
            y1 = y // k
            if x1 < 0:
                x1 = -x1
                y1 = -y1
            A.append((x1, y1))
        else:
            b +=1
    B = set(A)
    for m in B:
        if A.count(m) >= 2:
            c = A.count(m)
            n =  c * (c-1) / 2
            num += n

    if b >= 2:
        n = b * (b-1)  / 2
        num += n

sum = N * (N-1) * (N-2) / 6
ans = sum - num
print(int(ans))

3完できずレートがちょい下がりしたの悔やまれる. 次回挽回!!!

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?