HackerRank Hackerland Radio Transmitters
https://www.hackerrank.com/challenges/hackerland-radio-transmitters/problem
提出
code: python
#!/bin/python3
import math
import os
import random
import re
import sys
import bisect
#
# Complete the 'hackerlandRadioTransmitters' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER_ARRAY x
# 2. INTEGER k
#
def hackerlandRadioTransmitters(x, k):
# Write your code here
x.sort()
i, ans = 0, 0
while (i < n):
s = xi
i += 1
while (i < n and xi <= s + k):
i += 1
p = xi - 1
while (i < n and xi <= p + k):
i += 1
ans += 1
return ans
if __name__ == '__main__':
fptr = open(os.environ'OUTPUT_PATH', 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input0)
k = int(first_multiple_input1)
x = list(map(int, input().rstrip().split()))
result = hackerlandRadioTransmitters(x, k)
fptr.write(str(result) + '\n')
fptr.close()
メモ
蟻本 2-2 Saruman's Army