https://www.acmicpc.net/problem/11724 12345678910111213141516171819202122232425262728#include #include using namespace std; int n,m,u,v,c[1001],ans;vector a[1001]; void dfs(int x){ c[x]=1; for(auto i : a[x]) if(!c[i]) dfs(i);} int main(){ scanf("%d %d",&n,&m); while(m--) { scanf("%d %d",&u,&v); a[u].push_back(v); a[v].push_back(u); } for(int i=1;i
https://www.acmicpc.net/problem/2583 DFS로 연결 요소의 개수를 세준다. 12345678910111213141516171819202122232425262728293031323334353637#include #include #include using namespace std; int m,n,k,a,b,c,d,sum,map[101][101];int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};vector v; void dfs(int x,int y){ sum++,map[x][y]=1; for(int i=0;i
https://www.acmicpc.net/problem/1924 월마다 일수를 미리 배열에 넣어두고 현재 날짜까지 일수의 합을 구한 후 모듈러 값을 이용한다. 123456789101112#include int x,y,sum,m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};char *d[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"}; int main(){ scanf("%d %d",&x,&y); for(int i=0;i
https://www.acmicpc.net/problem/9375 map을 이용해서 옷 종류마다 개수를 세준다. 그리고 모든 가능한 경우는 (a+1)*(b+1)* ... *(z+1)와 같이 이항계수의 성질을 이용해서 구할 수 있다. 마지막에 옷을 안 입는 경우를 하나 빼준다. 1234567891011121314151617181920212223242526#include #include #include using namespace std; int main(){ int t,n; scanf("%d",&t); while(t--) { map m; scanf("%d",&n); while(n--) { string a,b; cin>>a>>b; m[b]++; } int ans=1; for(auto it=m.begin();..
https://www.acmicpc.net/problem/9009 그리디하게 가장 큰 피보나치 수부터 차례대로 정해 나간다. 12345678910111213141516171819202122#include #include using namespace std; int t,n,f[45]; int main(){ f[1]=1; for(int i=2;i=1;i--) if(n>=f[i]) s.push(f[i]),n-=f[i]; while(!s.empty()) printf("%d ",s.top()),s.pop(); printf("\n"); } return 0;}Colored by Color Scriptercs
https://www.acmicpc.net/problem/15789 일단 한솔 왕국이 포함된 동맹국들을 제외하고 CTP 왕국을 포함한 동맹국들과 나머지 동맹국 덩어리 중에 가장 큰 K개를 포함시킨다. DFS를 이용했다. 12345678910111213141516171819202122232425262728293031323334#include #include #include using namespace std; int n,m,x,y,c,h,k,l,v[100001],cnt,ans;vector a[100001],b; void dfs(int x){ v[x]=1,cnt++; for(auto i : a[x]) if(!v[i]) dfs(i);} int main(){ scanf("%d %d",&n,&m); while(m..