https://www.acmicpc.net/problem/2702 유클리드 호제법(Euclidean Algorithm)을 이용하여 최소공배수와 최대공약수를 구해준다. 12345678910111213141516#include int gcd(int a,int b) { return b?gcd(b,a%b):a; } int main(){ int t,a,b,g; scanf("%d",&t); while(t--) { scanf("%d %d",&a,&b); g=gcd(a,b); printf("%d %d\n",a*b/g,g); } return 0;}Colored by Color Scriptercs
https://www.acmicpc.net/problem/1939 정답(최대 중량제한)의 범위를 이분 탐색으로 줄여나가면서 최종 정답을 찾는다. BFS를 이용하여 답으로 정한 중량제한으로 시작점에서 도착점으로 갈 수 있는지 확인한다. 갈 수 있다면 범위를 올리면서 최대치를 찾고 갈 수 없다면 범위를 내린다. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657#include #include #include using namespace std; vector a[100001];int n,m,u,v,w,s,e; bool bfs(int w){ queue q; vector vis..
https://www.acmicpc.net/problem/1941 C(25,7)=480700가지의 모든 경우를 만들고 BFS로 7명이 인접해 있고 S가 4명 이상인지 확인한다. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#include #include #include using namespace std; char map[5][6];bool visit[5][5];int ans,dx[4]={0,0,-1,1},dy[4]={-1,1,0,0}; bool bfs(int sx,int sy){ int cnt=0,s=0; bool check[5]..