현대자동차그룹의 미래 모빌리티를 이끌어 나갈SW 우수인재를 위한 온라인 플랫폼
Challenge
Careers
Class
Connect
로그인 후 문제풀이가 가능합니다.
java 정답코드 - 확률값 변수 타입 유의
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] powers = new int[4]; for(int i = 0; i < 4; i++){ powers[i] = sc.nextInt(); } // 1. 전체 승패에 대한 모든 경우 생성 // [(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)] int[][] battleArr = {{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}}; LinkedList<String> battleStack = new LinkedList<>...
소수점 셋째자리까지 반올림
안녕하세요 고생 많으십니다. 다름이 아니라 자바의 Math.round를 활용해 반올림 처리를 해주려고 했는데 모든 히든 케이스에 대해서는 통과하고 첫 번째 케이스에 대해 통과가 되지 않아 이렇게 글을 남깁니다. answer = (float) (Math.round(answer*100000)/1000.0); 코드는 위와 같이 answer에 모든 확률 값들을 더해주고 이를 반올림하여 소수점 세 번째 자리까지 표기하였습니다. 예시로 주어진 테스트 케이스에 대한 확률 값들을 출력해보았을 때 아래와 같이 출력 되었습니다. 첫 번째 테스트 케이스에서 소수점 네 번째 자리의 4는 반올림 처리에서 버려지는 것이 아닌지 궁금합니다. 혹시 제가 잘못 생각한 부분이 있거나 놓친 부분에 대해서 알려주시면 감사하겠습니다...!
If it's incorrect in step 3! [Java]
You need to print up to the third decimal place. In the case of the double data type, since the values after the decimal point are not always the same, 50.000 might be printed as 50.0. Therefore, when printing, you need to explicitly specify the number of decimal places using printf.
python으로 해봤습니다.
import sys import itertools from decimal import Decimal, ROUND_HALF_UP input= sys.stdin.readline dic=[] F=list(map(int,input().strip().split(" "))) #1vs2 1vs3 1vs4 2vs3 2vs4 3vs4 daejin=[(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)] for x,y in daejin: a,b=F[x],F[y] dic.append([4*a/(5*(a+b)),(a+b)/(5*(a+b)),4*b/(5*(a+b))]) #모든 경우의수를 다 stack에 넣는다 3^6으로 721개나 함. #각 6개의대결에서 0vs1일경우 1이면 전자승 0이면 후자승 #0번이 2등안에 들만한 2채원배열을 스택으로 누적 #그래서[[1,1,1,0,0,0]] 스택 pop()에따라 (이런 결과가 일어날 확률)을 누적하는게 정답. stack = [list(item) f...
3번 케이스만 실패하네요 ㅠㅠ
다른 질문에서 반올림 이슈 등 소수점 문제로 보였는데, 아래 처럼해도 3번만 틀리네요. math.floor(prob * 1000 + 0.5) / 1000.0
[cpp] 테스트케이스 3번만 틀려요
#include<iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; // 0 win // 1 lose // 2 draw pair<int, int> arr[7] = { {0, 0}, {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4} }; double ans; double F[6]; double prob[6][6][3]; void dfs(int k, int rst, double tot, vector<int>& score) { int a = arr[k].first; int b = arr[k].second; double p = (rst == -1) ? 1.0 : prob[a][b][rst]; vector<int> tmp = score; if (rst == 0) score[a] += 3; else if (rst == 1) score[b] += 3; e...
완전 탐색인데 Subtask 1-3 안되는 이유가 잘 이해가 안가요
import sys F_1, F_2, F_3, F_4 = map(int, input().split()) case = [] case_detail = [] A_case = [3, 1, 0] B_case = [3, 1, 0] C_case = [3, 1, 0] D_case = [3, 1, 0] E_case = [3, 1, 0] F_case = [3, 1, 0] for a in A_case: for b in B_case: for c in C_case: for d in D_case: for e in E_case: for f in F_case: pt = [0,0,0,0] if a == 3: ...