'전체 글'에 해당되는 글 1802건

  1. 2019.08.12 [백준] ATM 11399
  2. 2019.08.09 node.js socket.io
  3. 2019.08.09 socket.io functions
  4. 2019.08.08 redux-example
  5. 2019.08.08 [리액트를 다루는기술] webpack.config.dev.js 파일이 없을 경우
  6. 2019.08.08 MySQL EXISTS

[백준] ATM 11399

Algorithm 2019. 8. 12. 13:59
반응형

https://www.acmicpc.net/problem/11399

 

11399번: ATM

첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)

www.acmicpc.net

문제

인하은행에는 ATM이 1대밖에 없다. 지금 이 ATM앞에 N명의 사람들이 줄을 서있다. 사람은 1번부터 N번까지 번호가 매겨져 있으며, i번 사람이 돈을 인출하는데 걸리는 시간은 Pi분이다.

사람들이 줄을 서는 순서에 따라서, 돈을 인출하는데 필요한 시간의 합이 달라지게 된다. 예를 들어, 총 5명이 있고, P1 = 3, P2 = 1, P3 = 4, P4 = 3, P5 = 2 인 경우를 생각해보자. [1, 2, 3, 4, 5] 순서로 줄을 선다면, 1번 사람은 3분만에 돈을 뽑을 수 있다. 2번 사람은 1번 사람이 돈을 뽑을 때 까지 기다려야 하기 때문에, 3+1 = 4분이 걸리게 된다. 3번 사람은 1번, 2번 사람이 돈을 뽑을 때까지 기다려야 하기 때문에, 총 3+1+4 = 8분이 필요하게 된다. 4번 사람은 3+1+4+3 = 11분, 5번 사람은 3+1+4+3+2 = 13분이 걸리게 된다. 이 경우에 각 사람이 돈을 인출하는데 필요한 시간의 합은 3+4+8+11+13 = 39분이 된다.

줄을 [2, 5, 1, 4, 3] 순서로 줄을 서면, 2번 사람은 1분만에, 5번 사람은 1+2 = 3분, 1번 사람은 1+2+3 = 6분, 4번 사람은 1+2+3+3 = 9분, 3번 사람은 1+2+3+3+4 = 13분이 걸리게 된다. 각 사람이 돈을 인출하는데 필요한 시간의 합은 1+3+6+9+13 = 32분이다. 이 방법보다 더 필요한 시간의 합을 최소로 만들 수는 없다.

줄을 서 있는 사람의 수 N과 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어졌을 때, 각 사람이 돈을 인출하는데 필요한 시간의 합의 최솟값을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)

출력

첫째 줄에 각 사람이 돈을 인출하는데 필요한 시간의 합의 최솟값을 출력한다.

예제 입력 1 복사

5 3 1 4 3 2

예제 출력 1 복사

32

출처

  • 문제를 만든 사람: baekjoon
  • 문제의 오타를 찾은 사람: hakgb11

알고리즘 분류

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
 
let people = 0;
let times = [];
let idx = 0;
 
 
rl.on("line", (answer)=>{
    if(idx == 0){
        people = answer;
    }else{
        times = answer.split(' ');
    }
    if(idx >=1){
        solution();
        rl.close();
    }
    idx++;
});
 
const solution = ()=>{
    let arr = [];
 
    times.forEach((num, i)=>{
        arr.push({ time: parseInt(num) });
    });
 
    arr.sort((a,b)=>{
        if(a.time > b.time) return 1;
        if(a.time < b.time) return -1;
        return 0;
    });
 
    let sum = 0;
    let total = 0;
    arr.forEach((person, i)=>{
        sum += person.time;
        total += sum;
    });
}
 
 
 
 
 
 

5
3 1 4 3 2
32

반응형

'Algorithm' 카테고리의 다른 글

[백준] 1463 1로 만들기  (0) 2019.08.13
[백준] 11047 동전 0 (진행중)  (0) 2019.08.13
설탕 배달  (0) 2019.06.11
그래프  (0) 2019.06.11
A* Pathfinding for Beginner By Patrick Lester  (0) 2019.05.22
:

node.js socket.io

Sever/Node.js 2019. 8. 9. 10:31
반응형

https://bcho.tistory.com/m/900

반응형

'Sever > Node.js' 카테고리의 다른 글

Node.js: Hello로 시작하는 Web 애플리케이션  (0) 2020.06.24
Node 다른 서버 API 호출  (0) 2020.06.11
socket.io functions  (0) 2019.08.09
mmserver  (0) 2019.07.10
Node.js에서 mysql을 async/await으로 작성하기  (0) 2019.01.16
:

socket.io functions

Sever/Node.js 2019. 8. 9. 10:27
반응형

https://dev.to/moz5691/socketio-for-simple-chatting---1k8n


socket.emit('message', "this is a test"); //sending to sender-client only
socket.broadcast.emit('message', "this is a test"); //sending to all clients except sender
socket.broadcast.to('game').emit('message', 'nice game'); //sending to all clients in 'game' room(channel) except sender
socket.to('game').emit('message', 'enjoy the game'); //sending to sender client, only if they are in 'game' room(channel)
socket.broadcast.to(socketid).emit('message', 'for your eyes only'); //sending to individual socketid
io.emit('message', "this is a test"); //sending to all clients, include sender
io.in('game').emit('message', 'cool game'); //sending to all clients in 'game' room(channel), include sender
io.of('myNamespace').emit('message', 'gg'); //sending to all clients in namespace 'myNamespace', include sender
socket.emit(); //send to all connected clients
socket.broadcast.emit(); //send to all connected clients except the one that sent the message
socket.on(); //event listener, can be called on client to execute on server
io.sockets.socket(); //for emiting to specific clients
io.sockets.emit(); //send to all connected clients (same as socket.emit)
io.sockets.on() ; //initial connection from a client.

반응형

'Sever > Node.js' 카테고리의 다른 글

Node 다른 서버 API 호출  (0) 2020.06.11
node.js socket.io  (0) 2019.08.09
mmserver  (0) 2019.07.10
Node.js에서 mysql을 async/await으로 작성하기  (0) 2019.01.16
nodejs mysql RESTful API (yellobean-server-00)  (0) 2019.01.08
:

redux-example

React 2019. 8. 8. 18:15
반응형

https://cjh5414.github.io/redux-example/

 

예제를 통한 Redux 이해하기

Jihun's Development Blog

cjh5414.github.io

 

반응형
:

[리액트를 다루는기술] webpack.config.dev.js 파일이 없을 경우

React 2019. 8. 8. 14:13
반응형

https://github.com/timarney/react-app-rewired/issues/370

 

for react-scripts 2.1.5, webpack.config.dev.js does not exit · Issue #370 · timarney/react-app-rewired

Hi, I upgrade "react-scripts" from 1.1.4 to 2.1.5. There is not a file called "webpack.config.dev.js" in "/node_modules/react-scripts/config/webpack.config.dev". Only ...

github.com

If you are using CRA 1.x, or react-scripts-ts, you need to remain with the 1.6.2 release of react-app-rewired. To downgrade, type npm install react-app-rewired@1.6.2 or yarn add react-app-rewired@1.6.2.

There were changes in CRA 2.x that included merging the webpack.config.dev.js and webpack.config.prod.js files into a single file webpack.config.js. While react-app-rewired tries to verify which version of CRA you're using and to fallback to the separate files for older versions, that test only works properly with CRA itself - not with alternative versions of react-scripts like react-scripts-ts.

Note for below: by "customised scripts", I mean things like "react-scripts-ts".

Basic compatibility:

  • If the version of react-scripts that you are using or that the customised scripts is based on is for CRA 1.x, use react-app-rewired 1.x branch (last release was 1.6.2).
  • If the version of react-scripts that you are using or that the customised scripts is based on is for CRA 2.x, use the react-app-rewired 2.x branch.
  • If you are using a customised version of react-scripts that was based on CRA 2.x, ask the people providing the customised version to pull in the CRA 2.1.2 change to the webpack config scripts that merged them together so that you can use the react-app-rewired branch 2.x properly.

https://github.com/velopert/learning-react/issues/51

 

163p webpack.config.dev.js 설정관련 CRA v2로 eject 하셨다면.. · Issue #51 · velopert/learning-react

CRA v2로 eject하신 분들이 계시다면..! 이제는 기본적으로 CSS Module을 지원하네요. 따라서 컴포넌트 스타일링 시에 CSS module을 사용하기 위해 webpack.config.dev.js 옵션을 바꿀 필요가 없어졌고, 기본에 App.css대신 App.module.css로 확장자만 변경한 후 import React, { Compone...

github.com

CRA v2로 eject하신 분들이 계시다면..!

이제는 기본적으로 CSS Module을 지원하네요.

따라서 컴포넌트 스타일링 시에 CSS module을 사용하기 위해 webpack.config.dev.js 옵션을 바꿀 필요가 없어졌고, 기본에 App.css대신 App.module.css로 확장자만 변경한 후

import React, { Component } from 'react'; import styles from './App.module.css'; console.log(styles); class App extends Component { render() { return ( <div className={styles.box}> asd </div> ); } } export default App;

위와 같이 사용하면 되네요! 혹시 막히신 분들은 이거 보고 실습해보시길..^^;;

책 보면서도 너무 유익해서 계속 개선해서 더 좋은 책이 될 수 있었으면 하는 마음에 이슈 올립니다~! 벨로퍼트님 항상 감사드립니돠!

반응형
:

MySQL EXISTS

카테고리 없음 2019. 8. 8. 09:42
반응형

https://yahwang.github.io/posts/35

 

MySQL에서 연관 서브쿼리 연산자 EXISTS 활용하기 - YA-Hwang 기술 블로그

MySQL에서 EXISTS 사용법에 대해 알아본다.

yahwang.github.io

1
select * from clans where exists (select * from clan_members where clans.clan_master_id = clan_member_id and clan_members.role = 1);
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

반응형
: