728x90
반응형

전체 글 120

백준 16202번 MST게임(C++)🚩

문제가 이해안되서 잘못 풀었는데 정점은 고정되어있고 턴마다 간선이 줄어드는것이다. 처음엔 간선들 사이에 여러개 트리가 있나? 했는데 그게 아니라 간선이 줄어드면서 똑같이 n개의 정점에 대하여 트리가 되는지 푸는 문제이다. 거기다 처음에 find()함수에 리턴을 = 이아니라 >m>>k; parent.assign(n+2,-1); vectorvisited; visited.assign(n+2,vector(n+2,false)); //간선 없애기 vectorpq; int x,y; for(int i=1;i>x>>y; pq.push_back({i,x,y}); visited[x][y]=true; } vectorans(k,0); int turn=0; //정점을 모두 사용한 트리군 트리가 되기만하면 되는게 아니라 //트리가..

백준 1774번 우주신과의 교감(C++)

모든 간선간의 거리를 구해서 작은순으로 정렬하고 이미 연결된 수 제외하고 n-v-1개까지 유니온시키기 좌표간 연결은 순번 을 부여해서 사용하면 된다. #include #include #include #include #include using namespace std; typedef tupletp; vectorparent; vectornum; double distance(double x1,double y1,double x2,double y2){ return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int find(int node){ if(parent[node]n>>m; double x,y; parent.assign(n+1,-1); num.assign(n+1,{0,0}); f..

백준 4195번 친구 네트워크(C++)

목록을 set에 저장해서 번호 부여해서 유니온 파인드 #include #include #include #include using namespace std; vectorparent; int find(int node){ if(parent[node]t; while(t--){ sets; cin>>n; string a,b; vectorarr; for(int i=0;i>a>>b; arr.push_back({a,b}); s.insert(a); s.insert(b); } mapnum; //번호 부여 int cnt=1; for(auto it=s.begin();it!=s.end();it++){ num[*it]=cnt;cnt++; } parent.assign(s.size()+1,-1); for(int i=0;i

백준 2529번 부등호(C++) 🚩

서로 다른 3글자라서 조합을 nCm 해야하나? 했는데 결국 순서가 정해질테고 그냥 제일 상위몇개만 하면되었다.. 어렵다 #include #include #include #include using namespace std; //숫자 배열을 문자열로 string turn(vectorarr){ string tmp=""; for(int i=0;i>n; vectorarr(n); for(int i=0;i>arr[i]; } //조합을 해야하지 않을까? 했는데 그냥 상관업나 vectormins(n+1); vectormaxs(n+1); for(int i=0;i

백준 10971번 외판원순회2 (C++) 🚩

next_permutation은 {1,2,3,4} 가 주어지면 1,2,4,3 과 같이 다음에 넘어갈 수열이 있으면 실행 prev_permutation은 {1,2,4,3}이면 {1,2,3,4} 과 같은게 있으면 실행한다. #include #include #include using namespace std; vectorarr; int cal(vectorvisited){ visited.push_back(visited[0]); //중간에 길 끊기면 경로 아님 int cnt=0; for(int i=0;i>n; vectorvisited; arr.assign(n,vector(n,0)); visited.assign(n,0); for(int i=0;iarr[i][j]; } visited[i]=i; } //1->2->3-..

728x90
반응형