baekjoon 20260215
This commit is contained in:
parent
fdd1a53d87
commit
27ae010fdf
58
code_study/Baekjoon/c/9466_1.c
Normal file
58
code_study/Baekjoon/c/9466_1.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
int T, N, G;
|
||||||
|
int select[100001], result[100001];
|
||||||
|
bool visited[100001], done[100001];
|
||||||
|
|
||||||
|
int solv();
|
||||||
|
void dfs(int num);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
scanf("%d", &T);
|
||||||
|
|
||||||
|
for(int t=0; t<T; t++) {
|
||||||
|
G = 0;
|
||||||
|
result[t] = solv();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<T; i++) printf("%d\n", result[i]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int solv() {
|
||||||
|
scanf("%d", &N);
|
||||||
|
|
||||||
|
for(int i=1; i<=N; i++) {
|
||||||
|
visited[i] = false;
|
||||||
|
done[i] = false;
|
||||||
|
scanf("%d", &select[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int n=1; n<=N; n++) {
|
||||||
|
dfs(select[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return N - G;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dfs(int num) {
|
||||||
|
if(done[num]) return;
|
||||||
|
|
||||||
|
visited[num] = true;
|
||||||
|
|
||||||
|
int next = select[num];
|
||||||
|
|
||||||
|
if(!visited[next]) dfs(next);
|
||||||
|
else if(visited[next] && !done[next]) {
|
||||||
|
int temp = 1;
|
||||||
|
while(next != num) {
|
||||||
|
temp++;
|
||||||
|
next = select[next];
|
||||||
|
}
|
||||||
|
G += temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
done[num] = true;
|
||||||
|
}
|
||||||
68
code_study/Baekjoon/c/9466_2.c
Normal file
68
code_study/Baekjoon/c/9466_2.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
int T, N, G;
|
||||||
|
int select[100001], result[100001];
|
||||||
|
bool visited[100001], done[100001];
|
||||||
|
|
||||||
|
int solv();
|
||||||
|
void dfs(int num);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
scanf("%d", &T);
|
||||||
|
|
||||||
|
for(int t=0; t<T; t++) {
|
||||||
|
G = 0;
|
||||||
|
result[t] = solv();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<T; i++) printf("%d\n", result[i]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int solv() {
|
||||||
|
scanf("%d", &N);
|
||||||
|
|
||||||
|
for(int i=1; i<=N; i++) {
|
||||||
|
visited[i] = false;
|
||||||
|
done[i] = false;
|
||||||
|
scanf("%d", &select[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int n=1; n<=N; n++) {
|
||||||
|
if(done[n]) continue;
|
||||||
|
dfs(select[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return N - G;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dfs(int num) {
|
||||||
|
int curr = num;
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
visited[curr] = true;
|
||||||
|
curr = select[curr];
|
||||||
|
|
||||||
|
if(visited[curr]) {
|
||||||
|
if(!done[curr]) {
|
||||||
|
int temp = 1;
|
||||||
|
int next = select[curr];
|
||||||
|
while(next != curr) {
|
||||||
|
temp++;
|
||||||
|
next = select[next];
|
||||||
|
}
|
||||||
|
G += temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
curr = num;
|
||||||
|
while(!done[curr]) {
|
||||||
|
done[curr] = true;
|
||||||
|
curr = select[curr];
|
||||||
|
}
|
||||||
|
}
|
||||||
1
code_study/Baekjoon/python/14652.py
Normal file
1
code_study/Baekjoon/python/14652.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print(*(lambda x : [x[2]//x[1], x[2]%x[1]])(list(map(int, input().split()))))
|
||||||
Loading…
x
Reference in New Issue
Block a user