def sqc(xa,ya,xb,yb,xc,yc) :
return ((xb - xa) * (yc - ya) - (xc - xa) * (yb - ya)) / 2
xa, ya, xb, yb = map(float,input().split())
n, m = map(int,input().split())
astra = []
sc = []
res, smax = 0, 0
for i in range(n) :
xc, yc = map(float,input().split())
astra.append((xc,yc))
sctmp = sqc(xa,ya,xb,yb,xc,yc)
if smax < abs(sctmp) :
smax = abs(sctmp)
#print(sctmp)
sc.append(sctmp)
for i in range(m) :
sp = sqc(xa,ya,xb,yb,xc,yc)
if smax < abs(sp) :
smax = abs(sp)
#print(sp)
for j in range(n) :
xd, yd = astra[j][0], astra[j][1]
if sp * sc[j] < 0 :
if smax < abs(sp * sc[j]) :
smax = abs(sp * sc[j])
print('{:.2f}'.format(smax))
У меня получилось.
N = int(input())
if N == 1:
exit(0)
bacteria = [0] * N
for i in range(0, N):
bacteria[i] = int(input())
prefix_sum = [bacteria[0]] * N
for i in range(1, N):
prefix_sum[i] = prefix_sum[i - 1] + bacteria[i]
ans = [0] * N
if bacteria[N-1] > bacteria[0]:
ans[N - 1] = 1
for i in reversed(range(2, N)):
if ans[i] == 1:
prev = i - 1
if prefix_sum[prev] > bacteria[i] and bacteria[0] < bacteria[prev]:
ans[prev] = 1
for i in range(N):
print(ans[i])
Объяснение:
g++-GNU C++ 8.3.1
def sqc(xa,ya,xb,yb,xc,yc) :
return ((xb - xa) * (yc - ya) - (xc - xa) * (yb - ya)) / 2
xa, ya, xb, yb = map(float,input().split())
n, m = map(int,input().split())
astra = []
sc = []
res, smax = 0, 0
for i in range(n) :
xc, yc = map(float,input().split())
astra.append((xc,yc))
sctmp = sqc(xa,ya,xb,yb,xc,yc)
if smax < abs(sctmp) :
smax = abs(sctmp)
#print(sctmp)
sc.append(sctmp)
for i in range(m) :
xc, yc = map(float,input().split())
sp = sqc(xa,ya,xb,yb,xc,yc)
if smax < abs(sp) :
smax = abs(sp)
#print(sp)
for j in range(n) :
xd, yd = astra[j][0], astra[j][1]
if sp * sc[j] < 0 :
if smax < abs(sp * sc[j]) :
smax = abs(sp * sc[j])
print('{:.2f}'.format(smax))
У меня получилось.
N = int(input())
if N == 1:
exit(0)
bacteria = [0] * N
for i in range(0, N):
bacteria[i] = int(input())
prefix_sum = [bacteria[0]] * N
for i in range(1, N):
prefix_sum[i] = prefix_sum[i - 1] + bacteria[i]
ans = [0] * N
if bacteria[N-1] > bacteria[0]:
ans[N - 1] = 1
for i in reversed(range(2, N)):
if ans[i] == 1:
prev = i - 1
if prefix_sum[prev] > bacteria[i] and bacteria[0] < bacteria[prev]:
ans[prev] = 1
for i in range(N):
print(ans[i])
Объяснение:
g++-GNU C++ 8.3.1