제가 다음과 같이 코드를 작성했는데, 100%까지 가다가 틀립니다.. 어떤게 문제일까요? 반례를 제시해주실 수 있나요? 감사합니다. https://www.acmicpc.net/problem/1068 import sys input = sys.stdin.readline n = int(input()) g = list(map(int, input().split())) m = int(input()) cnt = 0 def DFS(x): g[x] = -1 for i in range(n): if g[i] == x: DFS(i) DFS(m) for i in range(n): if g[i] != -1 and i not in g: cnt += 1 print(cnt)
최근에 다시 자바스크립트로 돌리면서, 기존에 파이썬으로 했던 것들 다시 모두 자바스크립트로 풀어보면서 문제 풀어보니, 발견했습니다. 이거 첫번째 가정을, 그리디로 접근하면 해결 안되는 문제인것같습니다. 이후 가정들은 당연히 그리디 관념으로 최적값 찾을 수 있는데, 첫번째 가정부터 그리디로 접근하면 해결되는 문제가 아니라서 어긋나기때문에, 그리디관념이 통하지 않는 문제인것같습니다. 완전탐색해버리거나, 시간 더 줄이려면 백트래킹 가지치기 해야하는 문제인것같습니다. 입력입니다! 7 172 67 183 65 179 61 178 62 177 63 170 72 181 60 기존 풀이(무조건 183선발) 가 내주는 답 : 3 감독 현수가 원할 것 같은 답 : 6 그리디로 가장 키 큰 사람 무조건 선발하는 과정이 풀이에서 오류인것같습니다. 183 선발 가정하고 cnt 값 구하고, 그다음 181 선발 가정하고 cnt값 구하고, 쭉 다음 순으로 선발 가정하고 cnt값 구하는데, 만약 어떤 사람 선발 가정하고 cnt값 구하는데 남은 사람 수 다 합해도 기존 Max cnt보다 적을 경우, 백트레킹 가지치기로 break 혹은 return 끊어버리는게 맞는것같습니다. 풀이1. 이중포문 const input = require("fs") .readFileSync("input.txt") .toString() .trim() .split("\n"); const n = parseInt(input[0]); const arr = Array.from(Array(5), () => []); for (let i = 0; i < n; i++) { arr[i] = Array.from(input[i + 1].trim().split(" ")).map((v) => parseInt(v)); } function solution(n, arr) { arr.sort((a, b) => b[0] - a[0]); let cnt = 0; let largest = 0; let res = 0; for (let i = 0; i < n; i++) { largest = arr[i][1]; cnt += 1; if (res >= n - i) { break; } for (let j = i + 1; j < n; j++) { if (arr[j][1] > largest) { largest = arr[j][1]; cnt += 1; } } res = Math.max(res, cnt); cnt = 0; } console.log(res); } solution(n, arr); 풀이2. DFS const input = require("fs") .readFileSync("input.txt") .toString() .trim() .split("\n"); const n = parseInt(input[0]); const arr = Array.from(Array(5), () => []); for (let i = 0; i < n; i++) { arr[i] = Array.from(input[i + 1].trim().split(" ")).map((v) => parseInt(v)); } let cnt = 0; let res = 0; //const list = []; function DFS(s, weight) { if (s < 0) return; if (cnt + n - s <= res) { cnt -= 1; s -= 1; return; } for (let i = s; i < n; i++) { if (arr[i][1] > weight) { cnt += 1; //list.push(arr[i][1]); DFS(i + 1, arr[i][1]); //list.pop(); } } res = Math.max(res, cnt); //console.log(list); cnt -= 1; } function solution(n, arr) { arr.sort((a, b) => b[0] - a[0]); DFS(0, 0); console.log(res); } solution(n, arr);
{ "compilerOptions": { "baseUrl": "src" }, "include": ["src"] } keonhongkoo@keonhongui-MacBookAir frontend % yarn start yarn run v1.22.19 $ react-scripts start node:internal/modules/cjs/loader:1325 throw err; ^ SyntaxError: /Users/keonhongkoo/Desktop/instagram/frontend/jsconfig.json: Unexpected token / in JSON at position 75 at parse (<anonymous>) at Module._extensions..json (node:internal/modules/cjs/loader:1322:39) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) at getModules (/Users/keonhongkoo/Desktop/instagram/frontend/node_modules/react-scripts/config/modules.js:126:14) at Object.<anonymous> (/Users/keonhongkoo/Desktop/instagram/frontend/node_modules/react-scripts/config/modules.js:142:18) at Module._compile (node:internal/modules/cjs/loader:1254:14) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) Node.js v18.14.1 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. 이렇게 결과가 출력되는데 해결책이 안보이네요... vscode도 재시작해봤습니다ㅠ
사용자 입력 예외처리를 하고 있는데, 1)문자 입력 시 오류 2)3자리 숫자가 아닐 경우 오류 다음과 같이 코드를 짰는데 1)의 경우 except 부분에서 "입력 오류"를 출력하지만 2)의 경우 "입력오류"가 출력되지 않고 그냥 재입력하게 되네요. 혹시 이유를 알 수 있나요? 또한 문자 입력 시 "숫자만 입력 가능합니다"를 출력 두자리수 입력 시 "세 자리 수를 입력하세요"를 출력 하도록 하려면 코드를 어떻게 수정해야 할까요? 감사합니다.! #세 자리 숫자만 입력할 수 있게 하는 함수 def input_check(msg, casting = int): while True: try: num = input(msg) # 사용자 입력 num_str = str(num) #맨 앞의 수가 0일경우 0이 잘려버리기 때문에 str을 따로 저장 if(casting(num) and len(num) == 3): return num_str except: print("입력 오류") continue
안녕하세요~! 아나콘다를 설치하면서 두가지 정도 질문이 있습니다 1) 2023.02.22날짜로 아나콘다 최신판을 설치하는데 그림과 같이 옵션사항에 환경변수 체크가 되지 않습니다 ㅠㅠ 업데이트 되면서 바뀐것인지 아나콘다 최신판에서 이 옵션을 선택하지 않아도 괜찮을까요?? 2) 2023.02.22날짜로 아나콘다 최신판에서는 파이썬 버전이 3.9버전인데 파이썬 공식버전으로는 3.11까지 배포가 되었습니다 버전 차이가 많이 나도 아나콘다를 설치하는게 사용에 더 편리할까요??
E/RecyclerView: No adapter attached; skipping layout E/RecyclerView: No adapter attached; skipping layout coinListFragment 에서 생성되는 오류라고 생해서 관련된 부분을 수정해보았으나 계속해서 오류가 생성되서 왜 생기는걸까? 궁금해서 질문드립니다. 오류와 관계없이 화면에 리사이클러뷰는 잘 나오기때문에 넘어가도 상관없겠다 싶지만서도 왜 저런 오류가 생기는지 궁금해서 질문 합니다. 처음에는 XML 상에서도 layoutManager 를 지정해줘야 하나 싶어서 했으나 나타났고, 다음으로는 context 관련 문제인가 싶어서 해당하는 부분을 수정하다가 오히려 더 오류가 발생하였습니다...ㅋㅋㅋ 기능에는 문제가 없기 때문에 넘어가도 괜찮지만 순수하게 궁금해서 질문합니다. 아니면 혹시, coinListFragment 쪽의 RecyclerView 가 아닌, Intro 에서 좋아하는 코인을 만들때 의 오류메시지 일까요?
이렇게 (N+2)*(N+2) list를 만들고 안에다가 복사해서 붙여넣어버리는 방법은 별로인가요? N = int(input()) input_list = [list(map(int, input().split())) for _ in range(N)] n_list = [[0] * (N + 2) for _ in range(N + 2)] for i in range(N): for j in range(N): n_list[i + 1][j + 1] = input_list[i][j]
Run 돌리면 자꾸 에러가 떠서 그냥 아무 코드 입력없이 새 프로젝트를 만들어 돌려도 다음과 같은 에러코드가 뜹니다. 원인이 무엇일까요?? 6 issues were found when checking AAR metadata: 1. Dependency 'androidx.appcompat:appcompat-resources:1.6.1' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs. :app is currently compiled against android-32. Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33. Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on). 2. Dependency 'androidx.appcompat:appcompat:1.6.1' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs. :app is currently compiled against android-32. Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33. Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on). 3. Dependency 'androidx.activity:activity:1.6.0' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs. :app is currently compiled against android-32. Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33. Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on). 4. Dependency 'androidx.core:core:1.9.0' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs. :app is currently compiled against android-32. Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33. Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on). 5. Dependency 'androidx.core:core-ktx:1.9.0' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs. :app is currently compiled against android-32. Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33. Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on). 6. Dependency 'androidx.annotation:annotation-experimental:1.3.0' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs. :app is currently compiled against android-32. Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33. Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on).
소수 개수 구하기 문제 언어 : 파이썬 내용: 제가 작성한 하위 코드 for문 두 개 돌렸을뿐인데 리미트 타임에러가 뜹니다.. 구글링 해서 emurate함수 써서 푼 문제는 정답이라고 뜹니다. 난이도 초급에 emurate함수 방식으로 써서 풀라는 의도는 아니라고 판단되어 문의 드립니다. 아래 코드가 에러인지, 제가 잘 못하고 있는지 궁금합니다. (입사 전에는 자바로 면접 보고 들어갔는데 입사 한 회사에서 사용하는 언어는 파이썬이라서 파이썬으로 코테 풀고 있는점도 참고해서 피드백 부탁드립니다) received_data = int(input()) list = [] for i in range(2,received_data+1): list.append(0) for i in range(2,received_data+1): if list[i-2]==0: for j in range(2,received_data+1): if j>i and j%i==0: list[j-2]=1 print(list.count(0))
안녕하세요. 강의 잘듣고 있습니다. 다만, 제가 이 강의부터 시작해서 그런지 용어에 대한 개념이 헷갈립니다. util 디렉토리와 source.kt 파일의 역할은 정확히 무엇인가요? util 디렉토리에 들어가는 파일들의 내용은 무엇이고, DataSource의 역할이 무엇인지 궁금합니다 ! 감사합니다..
이 강의에서 에러가 발생했습니다. 소스코드는 다음과 같습니다. import requests from bs4 import BeautifulSoup url = "https://www.naver.com/" response = requests.get(url) # 에러 발생한 부분 html = response.text soup = BeautifulSoup(html, 'html.parser') word = soup.select_one("#NM_set_home_btn") print(word.text) 위 코드중 response = requests.get(url) 위 부분에서 에러가 발생했습니다. [ 에러 내용 ] Max retries exceeded with url:강의에서 접속한 url 이런 에러가 나오고 Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available. 뒤에 이런 문장이 나옵니다. 에러 해결 방법은 무었인가요? [ 에러 전체 내용 ] 에러의 전체 내용은 다음과 같습니다. Exception has occurred: SSLError HTTPSConnectionPool(host='search.naver.com', port=443): Max retries exceeded with url: /search.naver?where=news&sm=tab_jum&query=%EC%82%BC%EC%84%B1%EC%A0%84%EC%9E%90 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available. During handling of the above exception, another exception occurred: urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='search.naver.com', port=443): Max retries exceeded with url: /search.naver?where=news&sm=tab_jum&query=%EC%82%BC%EC%84%B1%EC%A0%84%EC%9E%90 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) During handling of the above exception, another exception occurred: File "D:\crawling\05. 뉴스 제목과 링크 가져오기.py", line 4, in <module> response = requests.get("https://search.naver.com/search.naver?where=news&sm=tab_jum&query=%EC%82%BC%EC%84%B1%EC%A0%84%EC%9E%90") requests.exceptions.SSLError: HTTPSConnectionPool(host='search.naver.com', port=443): Max retries exceeded with url: /search.naver?where=news&sm=tab_jum&query=%EC%82%BC%EC%84%B1%EC%A0%84%EC%9E%90 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
안녕하세요 강의 막바지를 향해 달려가고 있던 중 궁금한 점이 있습니다. SelectActivity에서 다음 MainActivity로 넘어가기 위해 onClick 이벤트를 TextView를 통해 처리하는 것을 보았습니다. 그런데 SettingActivity에서는 Button을 생성하는 것을 보고 TextView를 통해 클릭 이벤트를 처리하는 것과 Button을 통해 이벤트를 처리하는 것에 대한 차이가 있는지 궁금합니다. 혹은 개발자님만의 상황에 따른 사용 기준이 따로 있나요?? 유익한 강의 너무 잘 듣고 있습니다. 감사합니다