20251115 baekjoon

This commit is contained in:
songyc macbook 2025-11-15 21:35:04 +09:00
parent 45a1658511
commit bc2418389d
3 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#include <stdio.h>
char get_sign(long long val, int overflow_count) {
if(overflow_count > 0) return '+';
if(overflow_count < 0) return '-';
return val == 0 ? '0' : val < 0 ? '-' : '+';
}
int main() {
int i = 3;
while(i--) {
int T;
scanf("%d",&T);
long long sum = 0;
int overflow = 0;
while(T--) {
long long n, prev = sum;
scanf("%lld", &n);
sum += n;
if(n > 0 && prev > 0 && sum < 0) overflow++;
else if(n < 0 && prev < 0 && sum > 0) overflow--;
}
printf("%c\n",get_sign(sum, overflow));
}
return 0;
}

View File

@ -0,0 +1,10 @@
axis = []
for _ in range(int(input())) :
axis.append(tuple(map(int, input().split())))
axis.append(axis[0])
area = 0
for i in range(len(axis)-1) :
area += axis[i][0]*axis[i+1][1] - axis[i][1]*axis[i+1][0]
print(round(abs(area)*0.5,1))

View File

@ -0,0 +1,27 @@
if let N = Int(readLine() ?? ""),
let line = readLine(),
let nums = line.split(separator: " ").compactMap({Int($0)}) as? [Int],
nums.count == N
{
var (L, R) = (0, N-1)
var (vL, vR) = (nums[L], nums[R])
var val = abs(vL + vR)
while L != R {
let temp = nums[L] + nums[R]
if val > abs(temp) {
(vL, vR) = (nums[L], nums[R])
val = abs(temp)
}
if temp > 0 {
R -= 1
}
else {
L += 1
}
}
print(vL, vR)
}