20251017 baekjoon
This commit is contained in:
parent
aae202bd28
commit
9de3692256
74
code_study/Baekjoon/c/1865.c
Normal file
74
code_study/Baekjoon/c/1865.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAX_SIZE 5200
|
||||||
|
#define MAX_NODE 501
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int start;
|
||||||
|
int end;
|
||||||
|
int time;
|
||||||
|
} Edge;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int T;
|
||||||
|
scanf("%d", &T);
|
||||||
|
|
||||||
|
Edge* edge = (Edge*)malloc(sizeof(Edge)*MAX_SIZE);
|
||||||
|
int* distance = (int*)malloc(sizeof(int)*MAX_NODE);
|
||||||
|
|
||||||
|
while(T--) {
|
||||||
|
int N, M, W;
|
||||||
|
scanf("%d %d %d",&N, &M, &W);
|
||||||
|
|
||||||
|
// ROAD
|
||||||
|
for(int i=0; i<2*M; i+=2) {
|
||||||
|
int S, E, T;
|
||||||
|
scanf("%d %d %d",&S, &E, &T);
|
||||||
|
|
||||||
|
Edge temp1 = {S, E, T};
|
||||||
|
Edge temp2 = {E, S, T};
|
||||||
|
|
||||||
|
edge[i] = temp1;
|
||||||
|
edge[i+1] = temp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// WORM HOLE
|
||||||
|
for(int i=0; i<W; i++) {
|
||||||
|
int S, E, T;
|
||||||
|
scanf("%d %d %d",&S, &E, &T);
|
||||||
|
|
||||||
|
Edge temp = {S, E, T*(-1)};
|
||||||
|
|
||||||
|
edge[2*M+i] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(distance, 0, sizeof(int)*MAX_NODE);
|
||||||
|
bool negative_cycle = false;
|
||||||
|
|
||||||
|
for(int n=0; n<N; n++) {
|
||||||
|
for(int i=0; i<2*M+W; i++) {
|
||||||
|
int s = edge[i].start;
|
||||||
|
int e = edge[i].end;
|
||||||
|
int t = edge[i].time;
|
||||||
|
|
||||||
|
if(distance[e] > distance[s] + t) {
|
||||||
|
distance[e] = distance[s] + t;
|
||||||
|
|
||||||
|
if(n==N-1) {
|
||||||
|
negative_cycle = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s\n", negative_cycle ? "YES" : "NO");
|
||||||
|
}
|
||||||
|
|
||||||
|
free(edge);
|
||||||
|
free(distance);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
88
code_study/Baekjoon/c/2638.c
Normal file
88
code_study/Baekjoon/c/2638.c
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} Point;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int N, M;
|
||||||
|
scanf("%d %d", &N, &M);
|
||||||
|
|
||||||
|
int** paper = (int**)malloc(sizeof(int*)*N);
|
||||||
|
int cheese = 0;
|
||||||
|
int time = 0;
|
||||||
|
|
||||||
|
for(int i=0; i<N; i++) {
|
||||||
|
paper[i] = (int*)malloc(sizeof(int)*M);
|
||||||
|
|
||||||
|
for(int j=0; j<M; j++) {
|
||||||
|
scanf("%d",&paper[i][j]);
|
||||||
|
|
||||||
|
if(paper[i][j] == 1) cheese++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int** visited = (int**)malloc(sizeof(int*)*N);
|
||||||
|
for(int i=0; i<N; i++) visited[i] = (int*)malloc(sizeof(int)*M);
|
||||||
|
Point* qu = (Point*)malloc(sizeof(Point)*(N*M));
|
||||||
|
|
||||||
|
while(cheese != 0) {
|
||||||
|
for(int i=0; i<N; i++) memset(visited[i], 0, sizeof(int)*M);
|
||||||
|
|
||||||
|
int q_front = 0;
|
||||||
|
int q_rear = 0;
|
||||||
|
|
||||||
|
Point start = {0,0};
|
||||||
|
qu[q_rear++] = start;
|
||||||
|
visited[0][0] = 1;
|
||||||
|
|
||||||
|
int dx[4] = {-1,1,0,0};
|
||||||
|
int dy[4] = {0,0,1,-1};
|
||||||
|
|
||||||
|
while(q_front != q_rear) {
|
||||||
|
Point now = qu[q_front++];
|
||||||
|
|
||||||
|
for(int i=0; i<4; i++) {
|
||||||
|
int nx = now.x + dx[i];
|
||||||
|
int ny = now.y + dy[i];
|
||||||
|
|
||||||
|
if(0<=nx && nx<M && 0<=ny && ny<N && paper[ny][nx] == 0 && visited[ny][nx] == 0) {
|
||||||
|
Point next = {nx, ny};
|
||||||
|
qu[q_rear++] = next;
|
||||||
|
visited[ny][nx] = 1;
|
||||||
|
|
||||||
|
for(int j=0; j<4; j++) {
|
||||||
|
int nnx = next.x + dx[j];
|
||||||
|
int nny = next.y + dy[j];
|
||||||
|
|
||||||
|
if(0<=nnx && nnx<M && 0<=nny && nny<N && paper[nny][nnx] == 1) visited[nny][nnx]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<N; i++) {
|
||||||
|
for(int j=0; j<M; j++) {
|
||||||
|
if(paper[i][j] == 1 && visited[i][j] > 1) {
|
||||||
|
paper[i][j] = 0;
|
||||||
|
cheese--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%d\n",time);
|
||||||
|
|
||||||
|
for(int i=0; i<N; i++) free(paper[i]);
|
||||||
|
free(paper);
|
||||||
|
for(int i=0; i<N; i++) free(visited[i]);
|
||||||
|
free(visited);
|
||||||
|
free(qu);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
8
code_study/Baekjoon/swift/2440.swift
Normal file
8
code_study/Baekjoon/swift/2440.swift
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
if let N = Int(readLine() ?? "") {
|
||||||
|
for n in 0..<N {
|
||||||
|
for _ in 0..<N-n {
|
||||||
|
print("*",terminator: "")
|
||||||
|
}
|
||||||
|
print()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user