728x90
반응형

전체 글 112

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

백준 1080번 행렬(C++)🚩🚩

실버1인데 어려웠다.. 일단 행렬 A,B 를 n*m으로 하면 계속 입력이 잘안되었다. 접근 1.다른부분 처음에 정리 -> 하나씩 바꾸기 -> 끊임없이 바꾸기? -> 안되면 무한루프.. 체크한 다른 부분 계속 바뀌는데 계속 n*m 행렬 확인하면 비효율적.. 정답 3x3 행렬단위만 바꿀수 있으므로 n-3,m-3까지만 체크하고 (i,j)를 왼쪽 꼭지점으로 생각하면 여길 체크하면 다음부턴 체크 할 필요가 없어짐(바꿀수 없으므로). 하나하나 다바꿔보고 안되면 안되는것! #include #include using namespace std; int main() { int n,m; cin>>n>>m; vectorA(n); vectorB(n); //n*n 숫자 입력으로 하면 안됨 string tmp; for(int i=..

2019 카카오 겨울 인턴십 호텔 방 배정(C++)

몇개 시간초과 뜸 #include #include #include using namespace std; maproom; long long find(long long node){ if(room[node]==0)return node; return room[node]=find(room[node]); } long long unions(long long x){ long long xp=find(x); room[xp]=xp+1; return xp; } vector solution(long long k, vector room_number) { vector answer; for(int i=0;i map 사용의 문제였다. map하면 시간초과 뜬다. unordered_map이 더 빠르다. #include #include #..

백준 1043번 거짓말(C++)🚩

어렵다.... 각 파티의 참석인원을 모두 체크해서 무리를 짓고 진실이어야만 하는 무리 체크 후 파티에서 한명만 뽑아서 그 친구의 루트 노드가 진실인지를 판별하면된다. 진실인지를 parent로 한번에 구현할수 있나? 고민하다 꼬여버리고 되는지는 잘 모르겠다. 어렵다.. #include #include #include using namespace std; vectorparent; vectortruth; int find(int node){ if(parent[node]>m; cin>>t; parent.assign(n+1,-1); truth.assign(n+1,0); for(int i=0;i>p; truth[p]=1; //진실 아는사람 } /* if(p==0){ coutnum; cin>>q; int first=q..

백준 16562번 친구비(C++) 🚩

29% 틀렸습니다 왜 안되는거야... #include #include #include using namespace std; vectorparent; int find(int node){ if(parent[node]>m>>k; vectorarr; arr.assign(n+1,0); parent.assign(n+1,-1); for(int i=1;i>arr[i]; } int v,w; for(int i=0;i>v>>w; unions(v,w); } //값이 더작은것을 택하기 mapM; long long k1=0; for(int i=1;ik){ cout>w; unions(v,w); } //값이 더작은것을 택하기 long long k1=0; for(int i=1;i

2024 카카오 겨울 인턴십 가장 많이 받은 선물 C++

#include #include #include #include #include using namespace std; //선물지수: 친구에게 준 - 받은 //가장 많은 선물 주고받을 친구 선물수 //선물지수 계산 mapreceived; mapgive; maptotal; //주고받은거 mapgives; int solution(vector friends, vector gifts) { int answer = 0; //주고받은거 정리 string a,b; for(int i=0;i>a>>b; give[a]++; received[b]++; gives[{a,b}]++; } //주고받은 기록 -> 선물지수 for(int i=0;i

728x90
반응형