전체 글 (306)
2022-03-09 08:01:25
반응형

평균 구하기

 

 문제 설명

 

N개의 마을로 이루어진 나라가 있습니다. 이 나라의 각 마을에는 1부터 N까지의 번호가 각각 하나씩 부여되어 있습니다. 각 마을은 양방향으로 통행할 수 있는 도로로 연결되어 있는데, 서로 다른 마을 간에 이동할 때는 이 도로를 지나야 합니다. 도로를 지날 때 걸리는 시간은 도로별로 다릅니다. 현재 1번 마을에 있는 음식점에서 각 마을로 음식 배달을 하려고 합니다. 각 마을로부터 음식 주문을 받으려고 하는데, N개의 마을 중에서 K 시간 이하로 배달이 가능한 마을에서만 주문을 받으려고 합니다. 다음은 N = 5, K = 3인 경우의 예시입니다.

위 그림에서 1번 마을에 있는 음식점은 [1, 2, 4, 5] 번 마을까지는 3 이하의 시간에 배달할 수 있습니다. 그러나 3번 마을까지는 3시간 이내로 배달할 수 있는 경로가 없으므로 3번 마을에서는 주문을 받지 않습니다. 따라서 1번 마을에 있는 음식점이 배달 주문을 받을 수 있는 마을은 4개가 됩니다.
마을의 개수 N, 각 마을을 연결하는 도로의 정보 road, 음식 배달이 가능한 시간 K가 매개변수로 주어질 때, 음식 주문을 받을 수 있는 마을의 개수를 return 하도록 solution 함수를 완성해주세요.

 

 제한 사항

 

 

  • 마을의 개수 N은 1 이상 50 이하의 자연수입니다.
  • road의 길이(도로 정보의 개수)는 1 이상 2,000 이하입니다.
  • road의 각 원소는 마을을 연결하고 있는 각 도로의 정보를 나타냅니다.
  • road는 길이가 3인 배열이며, 순서대로 (a, b, c)를 나타냅니다.
    • a, b(1 ≤ a, b ≤ N, a != b)는 도로가 연결하는 두 마을의 번호이며, c(1 ≤ c ≤ 10,000, c는 자연수)는 도로를 지나는데 걸리는 시간입니다.
    • 두 마을 a, b를 연결하는 도로는 여러 개가 있을 수 있습니다.
    • 한 도로의 정보가 여러 번 중복해서 주어지지 않습니다.
  • K는 음식 배달이 가능한 시간을 나타내며, 1 이상 500,000 이하입니다.
  • 임의의 두 마을간에 항상 이동 가능한 경로가 존재합니다.
  • 1번 마을에 있는 음식점이 K 이하의 시간에 배달이 가능한 마을의 개수를 return 하면 됩니다.

 

 

 입출력 예

 

N arr K result
5 [[1,2,1], [2,3,3], [5,2,2], [1,4,2], [5,3,1], [5,4,2]] 3 4
6 [[1,2,1], [1,3,2], [2,3,2], [3,4,3], [3,5,2], [3,5,3], [5,6,1]] 4 4

 

입출력 예 설명

입출력 예 #1
문제의 예시와 같습니다.

입출력 예 #2
주어진 마을과 도로의 모양은 아래 그림과 같습니다.


1번 마을에서 배달에 4시간 이하가 걸리는 마을은 [1, 2, 3, 5] 4개이므로 4를 return 합니다.

 

 Python 코드

 

플로이드워셜

def solution(N, road, K):
    INF = 1000000000
    answer = 0
    graph = [[INF] * (N + 1) for _ in range(N + 1)]
 
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if i == j:
                graph[i][j] = 0
 
    for r in road:
        a, b, c = r[0], r[1], r[2]
        if graph[a][b] > c:
            graph[a][b] = c
            graph[b][a] = c
 
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            for k in range(1, N + 1):
                graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k])
 
    for j in range(1, N + 1):
        if graph[1][j] <= K:
            answer += 1
 
    return answer

다익스트라 

from queue import PriorityQueue
 
 
def solution(N, road, K):
    INF = 1000000000
    answer = 0
    distance = [INF] * (N + 1)
 
    q = PriorityQueue()
    q.put([1, 0])
    distance[1] = 0
    while not q.empty():
        now, now_cost = q.get()
 
        if now_cost > distance[now]: continue
        for start, dest, cost in road:
            next_cost = now_cost + cost
            if start == now and next_cost < distance[dest]:
                distance[dest] = next_cost
                q.put([dest, next_cost])
            elif dest == now and next_cost < distance[start]:
                distance[start] = next_cost
                q.put([start, next_cost])
 
    for i in range(1, N + 1):
        if distance[i] <= K:
            answer += 1
 
    return answer

* 참고 링크 : https://foameraserblue.tistory.com/86

 

 C++ 코드

 

#include <vector>
#include <queue>
using namespace std;
 
vector<pair<int,int>> V[55];
vector<int> Dist;
 
int Min(int A, int B) { if (A < B) return A; return B; }
 
void Dijkstra(int N)
{
    priority_queue<pair<int, int>> PQ;
    PQ.push(make_pair(0, 1));
    Dist[1] = 0;
 
    while (PQ.empty() == 0)
    {
        int Cost = -PQ.top().first;
        int Cur = PQ.top().second;
        PQ.pop();
 
        for (int i = 0; i < V[Cur].size(); i++)
        {
            int Next = V[Cur][i].first;
            int nCost = V[Cur][i].second;
 
            if (Dist[Next] > Cost + nCost)
            {
                Dist[Next] = Cost + nCost;
                PQ.push(make_pair(-Dist[Next], Next));
            }
        }
    }
}
 
int solution(int N, vector<vector<int> > road, int K)
{
    Dist.resize(N + 1, 2e9);
    for (int i = 0; i < road.size(); i++)
    {
        int N1 = road[i][0];
        int N2 = road[i][1];
        int Dist = road[i][2];
 
        V[N1].push_back(make_pair(N2, Dist));
        V[N2].push_back(make_pair(N1, Dist));
    }
 
    Dijkstra(N);
    int answer = 0;
    for (int i = 1; i <= N; i++)
    {
        if (Dist[i] <= K) answer++;
    }
 
    return answer;
}

* 참고 링크 : https://yabmoons.tistory.com/633

 출처

 

https://programmers.co.kr/learn/courses/30/lessons/12978

반응형
2022-03-08 17:53:32
반응형

Spring Framework 용어 정리

 

 Spring Framework 용어 정리 1 (Version)

 

① Spring Framework Version : 4.3.30 release

② JDK Version : 1.8

③ DB Version : Oracle 11g Express Edition 

④ Servlet / JSP Version : 추후 확인 예정

⑤ Build Tool ( 빌드 툴 )

⑥ logging → logback

⑦ 버전관리 (형상관리) → Git / Github

 

 Spring Framework 용어 정리 2 (POJO & IoC & Bean)

① POJO (Plain Old Java Object)

- 어떠한 것도 implements & extends 하지 않음

- public class classname { } → 독립적 => 재사용 ↑

- Spring 환경에 의존적 X

 

② IoC (Inversion of Control : 제어의 역행)

 

③ Bean → 클래스를 의미

 

 Spring Framework 용어 정리 3 (IoC Container)

 

IoC Container

=> 궁극적인 기능 Bean들의 Life Cycle 관리 

=> IoC 기능을 담당하는 그릇

* IoC 기능 : 외부에서 Bean을 생성하고 필요 시 주입

 

 

 Spring Framework 용어 정리 4 (Spring Framework 개발 방법)

 

① xml 이용 : Bean 등록, 주입, ...

 

② @(어노테이션) + 최소한의 xml 이용

 

③ @(어노테이션) 이용 ( Java Coding Configuration )

* Spring Boot는 @(어노테이션) 기반

 

 Spring Framework 용어 정리 5 (AOP)

 

AOP ( Aspect Oriented Programming )

 

 

 Spring Framework 용어 정리 6 (Spring)

 

Spring → Java 기반

→ View를 생성하는 방법이 다양한 기술을 활용한다.

ex) JSP/Servlet, Velocity, thymeleaf => html(Spring Boot), pdf, excel, ... 

=>  View Resolve Bean 이용

JSP/Servlet 전담 View Resolver

Internal Resource View Resolver

 

 Spring Framework 용어 정리 7 (Spring Framework 실행 순서)

 

@ + 최소한의 xml 이용

① Bean 생성 (Class 생성)

② xml 등록

<bean id="" class="" />

③ IoC Container에게 xml 인식

//XXXXAplicationContext

ApplicationContext ctx = new GenericXmlApplicationContext("classpath:com/config/user.xml");

Bean 얻기

ctx.getBean("id", A.class);

 

 Spring Framework 용어 정리 8 (Bean 간의 사용)

 

 

 출처

 

 

+ 강의 교재

반응형
2022-03-04 14:43:09
반응형

Big Countries

 

 문제 설명

 

Create table If Not Exists World (name varchar(255), continent varchar(255), area int, population int, gdp int)Truncate table Worldinsert into World (name, continent, area, population, gdp) values ('Afghanistan', 'Asia', '652230', '25500100', '20343000000')insert into World (name, continent, area, population, gdp) values ('Albania', 'Europe', '28748', '2831741', '12960000000')insert into World (name, continent, area, population, gdp) values ('Algeria', 'Africa', '2381741', '37100000', '188681000000')insert into World (name, continent, area, population, gdp) values ('Andorra', 'Europe', '468', '78115', '3712000000')insert into World (name, continent, area, population, gdp) values ('Angola', 'Africa', '1246700', '20609294', '100990000000')

 

able: World

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| name        | varchar |
| continent   | varchar |
| area        | int     |
| population  | int     |
| gdp         | int     |
+-------------+---------+
name is the primary key column for this table.
Each row of this table gives information about the name of a country, the continent to which it belongs, its area, the population, and its GDP value.

 

A country is big if:

  • it has an area of at least three million (i.e., 3000000 km2), or
  • it has a population of at least twenty-five million (i.e., 25000000).

Write an SQL query to report the name, population, and area of the big countries.

Return the result table in any order.

The query result format is in the following example.

 

 입출력 예

 

Example 1:

Input: 
World table:
+-------------+-----------+---------+------------+--------------+
| name        | continent | area    | population | gdp          |
+-------------+-----------+---------+------------+--------------+
| Afghanistan | Asia      | 652230  | 25500100   | 20343000000  |
| Albania     | Europe    | 28748   | 2831741    | 12960000000  |
| Algeria     | Africa    | 2381741 | 37100000   | 188681000000 |
| Andorra     | Europe    | 468     | 78115      | 3712000000   |
| Angola      | Africa    | 1246700 | 20609294   | 100990000000 |
+-------------+-----------+---------+------------+--------------+
Output: 
+-------------+------------+---------+
| name        | population | area    |
+-------------+------------+---------+
| Afghanistan | 25500100   | 652230  |
| Algeria     | 37100000   | 2381741 |
+-------------+------------+---------+

 

 Oracle Query

 

select name, population, area 
from world 
where area >= 3000000 or population >= 25000000;

 

 

 출처

 

https://leetcode.com/problems/big-countries/

반응형
2022-03-03 17:45:40
반응형

jQuery 다운로드 & CDN 방식 적용

 

 jQuery 다운로드

 

* jQuery 다운로드 방식

https://jquery.com/download/

 

Download jQuery | jQuery

link Downloading jQuery Compressed and uncompressed copies of jQuery files are available. The uncompressed file is best used during development or debugging; the compressed file saves bandwidth and improves performance in production. You can also download

jquery.com

 

1. jQuery 사이트 접속 → Download → Download the compressed, production jQuery 3.6.0 &

Download the uncompressed, development jQuery 3.6.0 마우스 우클릭하여 다른 이름으로 링크 저장

2. Eclipse에서 생성한 프로젝트 - WebContent - jQuery 작업할 경로에 복사

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-3.6.0.min.js"></script> <!-- jQuery 다운 받음 -->
<script type="text/javascript">

	// jQuery Code 작업
	console.log($(document));

</script>
</head>
<body>
</body>
</html>

 

 CDN 방식 - Google

https://developers.google.com/speed/libraries#jquery

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">
</script><!-- CDN 방식 -->
<script type="text/javascript">

	// jQuery Code 작업
	console.log($(document));

</script>
</head>
<body>
</body>
</html>

 

 출처

 

 

+ 강의 교재

반응형
2022-03-01 08:32:31
반응형

연결 - 라이브 vs 추출

 

(1) Tableau public version은 지원 안하며, Tableau Desktop version만 지원

라이브 - 항상 데이터베이스를 향해 직접적으로 쿼리를 날림

추출 - 데이터베이스 현재 상태를 스캔본으로 뜨는 것과 같음

(해당 스캔본을 local pc에 저장하기 때문에 처리 속도 빠름)

 

필터

 

(2) 데이터 원본 필터

 

 

 출처

 

웰컴 투 태블로 월드

https://www.inflearn.com/course/%ED%83%9C%EB%B8%94%EB%A1%9C%EA%B0%95%EC%A2%8C-1

 

 

 

+ 강의 교재

반응형
2022-02-25 17:43:24
반응형

Contains Duplicate 

 

 문제 설명

 

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

 

 제한 사항

 

 

  • 1 <= nums.length <= 105
  • -109 <= nums[i] <= 109

 

 

 입출력 예

 

Example 1:

Input: nums = [1,2,3,1]
Output: true

Example 2:

Input: nums = [1,2,3,4]
Output: false

Example 3:

Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true

 

 

 Python 코드

 

Python code 

class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
        return len(set(nums)) != len(nums)

* 참고 링크 : https://leetcode.com/problems/contains-duplicate/discuss/1159570/Python-99.25-faster

https://leetcode.com/problems/contains-duplicate/discuss/471215/Python-sol-by-native-set-and-length.-run-time-90%2B

 

class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
    	hashset = set()
        
        for n in nums:
        	if n in hashset:
            	    return True
        	hashset.add()
        return False

* 참고 링크 : https://www.youtube.com/watch?v=3OamzN90kPg 

 

 C++ 코드

 

C ++ code

class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        unordered_map<int,bool> map;
        for(size_t i = 0;i<nums.size();++i)
        {
            if(map[nums[i]]==true)
                return true;
            map[nums[i]]=true;
        }
        return false;
    }
};

* 참고 링크 : https://kkminseok.github.io/posts/leetcode_Contains_Duplicate/

 

 출처

 

https://leetcode.com/problems/contains-duplicate/

반응형