1
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.

A - Round One, A - One Card Poker, D - Derangement

Last updated at Posted at 2021-02-14

2021/2/14
くじかつ、精進内容

##A - Round One

O(1)
xorで必要な数を取り出します。

python
A = int(input())
B = int(input())
 
res = ((1^2^3)^A)^B
print(res)

##A - One Card Poker

O(1)
実装問題、13と1の時だけ条件式が必要です。

python
A, B = list(map(int, input().split()))
 
if A == 13 and B == 1:
  print("Bob")
elif A == 1 and B == 13:
  print("Alice")
elif A > B:
  print("Alice")
elif A < B:
  print("Bob")
else:
  print("Draw")

##D - Derangement

O(N)
実装問題、最後の要素だけ別で処理を行います。

python
import math
import heapq
import itertools

def main():
    N = int(input())
    P = list(map(int, input().split()))
 
    cnt=0
    for i in range(0, N):
        if P[i] == i+1 and i < N-1:
            P[i], P[i+1] = P[i+1], P[i]
            cnt+=1
        elif P[i] == i+1 and i == N-1:
            P[i], P[i-1] = P[i-1], P[i]
            cnt+=1
    
    print(cnt)
 
 
# エントリポイント
if __name__ == '__main__':
    main()

##まとめ
緑diffの問題は過去に記事を作成しています。

1
0
0

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
1
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?