회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
반례 좀 주시면 감사하겠습니다.
17143번 - 낚시왕
ghjo92
4년 전
0
흠 예제나 질문들에 써있는 반례들은 다 맞는거 같아서 질문 올립니다.
반례나 틀린 부분 좀 봐주시길 부탁드립니다.
#include <iostream> #include <vector> #include <math.h> using namespace std; int R, C, N; struct sh { int r, c; //위치 int s; //속력 int d; //방향 1위2아래3오른쪽4왼쪽 int z; //크기 }; /* struct bd { int sz; int state; // 0없음 1이동완료물고기 2죽은물고기 }; */ vector<sh> vsh; vector<sh>nextvsh; int board[101][101]; //상어의 크기, -1 이면 죽은거 int ans; int main() { //초기화 for (int i = 1; i <= R; i++) { for (int j = 1; j <= C; j++) { board[i][j] = 0; } } ans = 0; //입력 cin >> R >> C >> N; for (int i = 0; i < N; i++) { sh tempsh; cin >> tempsh.r >> tempsh.c >> tempsh.s >> tempsh.d >> tempsh.z; board[tempsh.r][tempsh.c] = tempsh.z; vsh.push_back(tempsh); } //시작 int itime = 0; // 시간. 사냥꾼위치 while (itime != C) { //이동 itime++; //상어잡기 int ir = 1; while (board[ir][itime] == 0 && ir <= R) { ir++; } if (ir <= R) { ans += board[ir][itime]; //정답계산 board[ir][itime] = -1; //죽은 상어 처리 } //다시초기화 for (int i = 1; i <= R; i++) { for (int j = 1; j <= C; j++) { if (board[i][j] != -1) board[i][j] = 0; } } //상어이동 while (!vsh.empty()) { sh tempsh = vsh.back(); vsh.pop_back(); //죽은 상어면 건너뜀 if (board[tempsh.r][tempsh.c] == -1) { board[tempsh.r][tempsh.c] = 0; continue; } //이동 int dr[5] = { 0,-1,1,0,0 }; int dc[5] = { 0,0,0,1,-1 }; int nowr = tempsh.r; int nowc = tempsh.c; int nows = tempsh.s; int nowd = tempsh.d; while (nows != 0) { int nextr = nowr + dr[nowd] * nows; int nextc = nowc + dc[nowd] * nows; if (nextr >= R || nextr <= 1) { if (nextr > R) nextr = R; else if (nextr < 1) nextr = 1; if (nowd == 1) nowd = 2; else if (nowd == 2) nowd = 1; } if (nextc >= C || nextc <= 1) { if (nextc > C) nextc = C; else if (nextc < 1) nextc = 1; if (nowd == 3) nowd = 4; else if (nowd == 4) nowd = 3; } if (nowd == 1 || nowd == 2) nows = nows - abs(nowr - nextr); else if (nowd == 3 || nowd == 4) nows = nows - abs(nowc - nextc); nowr = nextr; nowc = nextc; } //물고기가 클경우만 넣는다. if (board[nowr][nowc] < tempsh.z) { board[nowr][nowc] = tempsh.z; tempsh.r = nowr; tempsh.c = nowc; tempsh.d = nowd; nextvsh.push_back(tempsh); } } while (!nextvsh.empty()) //잡아먹힌 물고기 제외 { sh tempsh = nextvsh.back(); nextvsh.pop_back(); if(board[tempsh.r][tempsh.c] == tempsh.z) vsh.push_back(tempsh); } } cout << ans; return 0; }
댓글을 작성하려면
로그인
해야 합니다.
ghjo92 4년 전
흠 예제나 질문들에 써있는 반례들은 다 맞는거 같아서 질문 올립니다.
반례나 틀린 부분 좀 봐주시길 부탁드립니다.