728x90
반응형

전체 글 112

백준 8980번 택배(C++)🚩

접근 방식 - 택배를 빨리 내릴수 있는걸 우선으로 담아야 최대한 많이 담을수 있다. 처음부터 끝까지 가서 계속 자리만 차지하는 택배를 없애야하는것.. - 정렬해서 처음-도착 위치에 지금 최대 택배를 몇번 담을수 있는지 차례로 계산한다. #include #include #include #include using namespace std; struct info{ int x; int y; int z; }; bool cmp(info a, info b){ if(a.y==b.y){ if(a.z==b.z){ return a.x>w; int m; cin>>m; int a,b,c; for(int i=0;i>a>>b>>c; t.push_back({a,b,c}); } sort(t.begin(),t.end(),cmp); //..

백준 17472번 다리만들기2 (C++) 🚩

런타임에러 요즘 왜 자꾸 런타임에러가 뜨지 #include #include #include #include #include using namespace std; typedef tuple tp; priority_queuepq; vectorarr; vectorvisited; mapinfo; int dr[4]={0,0,1,-1}; int dc[4]={1,-1,0,0}; int n,m; vectorparent; int find(int node){ if(parent[node]>m; parent.assign(n+1,-1); arr.assign(n,vector(m,0)); visited.assign(n,vector(m,false)); for(int i=0;iarr[i][j]; } } //섬을 지정하기 int num=..

백준 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

728x90
반응형