-
5644. [모의 SW 역량테스트] 무선 충전SWexpertAcademy 2019. 7. 24. 21:39
#include<cstdio> #include<queue> #include<vector> #include<iostream> #include<utility> using namespace std; struct bat{ int x; int y; int scale; int charge; int numb; }; int map[8][21][21]; bool d[8][21][21]; int m, a; int tc; int c[5] = { 1, 5, 21, 85, 341}; int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; int dx1[] = {0,-1,0,1,0}; int dy1[] = {0,0,1,0,-1}; int max(int a, int b){ int max = a; if(max < b) max = b; return max; } bool checking(int xa, int ya, int xb, int yb){ for(int i = 0; i < a; i++){ if(map[i][ya][xa] == 0 && map[i][yb][xb] == 0) continue; if (map[i][ya][xa] == map[i][yb][xb]) return true; } return false; } void save(vector<int>&a_s , vector<int>&b_s, int xa,int ya,int xb, int yb){ for(int i = 0; i < a; i++){ a_s.push_back(map[i][ya][xa]); b_s.push_back(map[i][yb][xb]); } } void make_map(int y, int x, int scale, int charge, int numb){ queue<pair<int, int>> q; q.push(make_pair(y,x)); map[numb][y][x] = charge; d[numb][y][x] = true; int sick = 1; while(!q.empty()){ y = q.front().first; x = q.front().second; q.pop(); for(int i = 0; i < 4; i++){ sick++; int nx = x + dx[i] ; int ny = y+ dy[i]; if(nx > 0 && nx <= 20 && ny > 0 && ny <= 20){ d[numb][ny][nx] = true; map[numb][ny][nx] = charge; q.push(make_pair(ny, nx)); } else{ q.push(make_pair(NULL, NULL)); } } if(sick == c[scale]) break; } } void initial(){ for(int i = 0; i < a; i++){ for(int j = 1; j <= 10; j++){ for(int k = 1; k <= 10; k++){ map[i][j][k] = 0; } } } } int main(){ cin>>tc; for(int al = 1; al<= tc; al++){ cin>>m >> a; vector<int> move_b; vector<int> move_a; for(int i = 0; i < m; i++){ int move; cin>>move; move_a.push_back(move); } for(int i = 0; i < m; i++){ int x; cin>>x; move_b.push_back(x); } bat battery; vector<bat> info_bat; for(int i = 0; i < a; i++){ cin>>battery.y; cin>>battery.x; cin>>battery.scale; cin>>battery.charge; battery.numb = i; info_bat.push_back(battery); } for(int i = 0; i < a; i++){ make_map(info_bat[i].y, info_bat[i].x, info_bat[i].scale ,info_bat[i].charge, info_bat[i].numb); } /*for(int i = 0; i < a; i++){ for(int j = 1; j <= 10; j++){ for(int k = 1; k <= 10; k++){ printf("%5d", map[i][j][k]); } cout<<endl; } cout<<endl; }*/ int xa = 1; int ya = 1; int xb = 10; int yb = 10; int result = 0; /*for(int i = 0; i < a; i++){ for(int k = 1; k <= 10; k++){ for(int j = 1; j <= 10; j++){ printf("%5d", map[i][k][j]); } cout<<endl; } cout<<endl; }*/ if(checking(xa,ya,xb,yb)== false){ int tempA = map[0][ya][xa]; int tempB = map[0][yb][xb]; for(int j = 0; j < a; j++) { if (tempA < map[j][ya][xa]) { tempA = map[j][ya][xa]; } if (tempB < map[j][yb][xb]) { tempB = map[j][yb][xb]; } } result = tempA+ tempB; } for(int i = 0; i < m; i++){ int tempa = move_a[i]; int tempb = move_b[i]; xa += dx1[tempa]; ya += dy1[tempa]; xb += dx1[tempb]; yb += dy1[tempb]; //cout<<ya<<" "<<xa<<" "<<yb<<" "<<xb<<endl; int tempA = 0; int tempB = 0; if(checking(xa,ya,xb,yb)== false){ for(int j = 0; j < a; j++) { if (tempA < map[j][ya][xa]) { tempA = map[j][ya][xa]; } if (tempB < map[j][yb][xb]) { tempB = map[j][yb][xb]; } } //cout<<"#"<<i<<" "<<tempA<<" "<<tempB<<endl; result += tempA + tempB; } else{ vector<int> a_s; vector<int> b_s; save(a_s, b_s, xa,ya,xb,yb); int temping = 0; for(int j = 0; j < a_s.size(); j++){ for(int k = 0; k < a_s.size(); k++){ if(a_s[j] == b_s[k]){ temping = max(temping, (a_s[j] + b_s[k]) / 2); } else{ temping = max(temping , a_s[j] + b_s[k]); } } } result += temping; } } cout<<"#"<<al<<" "<<result<<endl; initial(); } return 0; }
좀 많이긴데.. 그냥 bfs로 맵만들고 상황따라서 값 획득하는 시스템, main함수에서 계속 돌려서 그런지 코드가길어졌다
'SWexpertAcademy' 카테고리의 다른 글
5653. [모의 SW 역량테스트] 줄기세포배양 (0) 2019.07.26 5650. [모의 SW 역량테스트] 핀볼 게임 (0) 2019.07.25 7699. 수지의 수지 맞는 여행 (0) 2019.07.20 5658. [모의 SW 역량테스트] 보물상자 비밀번호 (0) 2019.07.15 1486. 장훈이의 높은 선반 (0) 2019.07.15