문제 URL : https://www.acmicpc.net/problem/2617
문제 접근법 :
플로이드를 와샬 알고리즘을 이용하여 쉽게 풀수있습니다.
해당 구슬이 다른구슬보다 큰것이 n/2보다 많은지
해당 구슬이 다른구슬보다 작은것이 n/2보다 많은지 확인해서 값을 구하면됩니다.
소스코드 :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
//By콩순이냉장고
#include <bits/stdc++.h>
using namespace std;
int w[101][101];
int n,m;
void input(){
cin>>n>>m;
int a,b;
for(int i=0;i<m;i++){
cin>>a>>b;
w[b][a]=1;
}
}
void floyed(){
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(w[i][k]&&w[k][j])
w[i][j]=1;
}
}
}
}
void print(){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<w[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
void solve(){
floyed();
int sum=0;
for(int i=1;i<=n;i++){
int cnt1=0,cnt2=0;
for(int j=1;j<=n;j++){
if(w[i][j])cnt1++;
if(w[j][i])cnt2++;
}
sum+=(cnt1>n/2||cnt2>n/2);
}
cout<<sum<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
input();
solve();
}
|
cs |
궁금한점 혹은 모르는점 어떤질문이든 댓글은 언제나 환영입니다.
'백준' 카테고리의 다른 글
백준 16404 주식회사 승범이네 (0) | 2023.01.18 |
---|---|
백준 2610 회의준비 (0) | 2023.01.18 |
백준 8012 한동이는 영업사원! (0) | 2023.01.18 |
백준 15480 LCA와 쿼리 (0) | 2023.01.18 |
백준 14676 영우는 사기꾼? (0) | 2022.11.15 |