회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
처음부터 바로 틀립니다... 도와주세요
17143번 - 낚시왕
jyunni
3년 전
0
질문게시판에 있는 반례들도 넣어봤는데 잘 나옵니다... 어디가 문제인걸까요?
class Program { public static int Width, Height, Count; //상어 겹칩을 검사하기 위한 배열 public static Shark?[,] exist; static void Init() { var input = Parsing; Width = input[1]; Height = input[0]; Count = input[2]; for (int i = 0; i < Count; i++) { Shark s = new(Parsing); if (s.x == meX) { if (target is null || target.y > s.y) target = s; } sharks.Add(s); } } //현재 낚시왕의 위치 private static int meX = 0; //현재 살아있는 상어들 private static HashSet<Shark> sharks = new(); //낚시왕의 위치와 같은 x좌표, 그리고 y값이 가장 작은 상어, 없으면 null private static Shark? target; static int[] Parsing => Array.ConvertAll(Console.ReadLine().Split(),int.Parse); //잡은 상어의 무게 private static int result = 0; //새로고침 static void Update() { //상어 낚시 if (target is not null) { result += target.scale; sharks.Remove(target); target = null; } //낚시왕의 위치 옮기기 meX++; exist = new Shark?[Width, Height]; foreach (var s in sharks) { s.Update(); if (exist[s.x, s.y] is null) { exist[s.x, s.y] = s; if (s.x == meX) { if (target is null || target.y > s.y) target = s; } } else { if (exist[s.x, s.y].scale > s.scale) sharks.Remove(s); else { if (target == exist[s.x, s.y]) { target = s; } sharks.Remove(exist[s.x, s.y]); } } } } static void Main() { Init(); for(int i=0;i<Width;i++) Update(); Console.Write(result); } } class Shark { public int x, y, speed, direction, scale; public Shark(int[] input) { this.x = input[1]-1; this.y = input[0]-1; this.speed = input[2]; this.direction = input[3]; this.scale = input[4]; } public void Update() { for (int i = 0; i < this.speed; i++) { this.Move(); } } void Move() { Retry: switch (this.direction) { case 1: if (this.y <= 0) { this.direction = 2; goto Retry; } this.y--; break; case 2: if (this.y >= Program.Height - 1) { this.direction = 1; goto Retry; } this.y++; break; case 3: if (this.x >= Program.Width - 1) { this.direction = 4; goto Retry; } this.x++; break; case 4: if (this.x <= 0) { this.direction = 3; goto Retry; } this.x--; break; } } }
댓글을 작성하려면
로그인
해야 합니다.
jyunni 3년 전
질문게시판에 있는 반례들도 넣어봤는데 잘 나옵니다... 어디가 문제인걸까요?