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 | import tensorflow as tf import keras import numpy as np from keras.datasets import imdb (train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000) #print("train_data[0] : ") #print(train_data[0]) print(max([max(sequence) for sequence in train_data])) word_index = imdb.get_word_index() reverse_word_index = dict([value, key] for(key, value) in word_index.items()) decoded_review = ''.join([reverse_word_index.get(i-3, '?') for i in train_data[0]]) print(decoded_review) def vectorize_sequences(sequences, dimension=10000): results = np.zeros((len(sequences), dimension)) for i, sequence in enumerate(sequences): results[i, sequence] = 1. return results x_train = vectorize_sequences(train_data) x_test = vectorize_sequences(test_data) print(x_train) |
Labels
Programming
(16)
Algorithm
(15)
Java
(15)
ASP .NET
(4)
Enterprise Architecture
(4)
PHP and MySQL
(4)
Software Engineering
(2)
C#
(1)
Data Mining
(1)
Deep Learning
(1)
Java Script
(1)
Python
(1)
Thursday, January 16, 2020
Binary Classifiation
Binary Classification
Thursday, November 10, 2016
Lucky Box
public class LuckyBox {
public static void main(String[] args) {
// TODO Auto-generated method stub
int N = 5;
int M = 5;
int[] values = {1, 2, 3, 1, 1};
}
}
Eight Queens
public class EightQueens {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 8;
enumerate(n);
}
public static void enumerate(int n){
int[] a = new int[n];
enumerate(a, 0);
}
public static void enumerate(int[] q, int k){
int n = q.length;
if(k == n)
printQueens(q);
else{
for(int i=0; i
if(isConsistent(q, k))
enumerate(q, k+1);
}
}
}
public static boolean isConsistent(int[] q, int n){
for(int i=0; i
return false;
if((q[i] - q[n]) == (n-i)) //same major diagonal (upper left entry to lower right entry)
return false;
if((q[n] - q[i]) == (n-i)) //same minor diagonal (upper right entry to lower left entry)
return false;
}
return true;
}
public static void printQueens(int[] q){
int n = q.length;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (q[i] == j)
System.out.print("Q ");
else
System.out.print("* ");
}
System.out.println();
}
System.out.println();
}
}
Valuntary
public class Valuntary {
public static int maxCost = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 4;
int input[][] = {{4,1,2,3},{3,1,2,4},{2,1,4,3},{3,1,2,4}};
enumerate(n, input);
System.out.println("Max Cost : "+maxCost);
}
public static void enumerate(int n, int[][] input){
int[] a = new int[n];
enumerate(a, 0, input);
}
public static int enumerate(int[] a, int k, int[][] input){
int cost = 0;
int n = a.length;
if(k == n){
cost = computeCost(a, input);
if(maxCost < cost){
maxCost = cost;
}
}
else{
for(int i=0; i
if(isConsistent(a, k)){
enumerate(a, k+1, input);
}
}
}
return cost;
}
public static boolean isConsistent(int[] a, int n){
for(int i=0; i
return false;
}
return true;
}
public static int computeCost(int[] a, int[][] input){
int n = a.length;
for(int i=0; i
if (a[i] == j)
System.out.print("O ");
else
System.out.print("* ");
}
System.out.println();
}
int cost = 0;
for(int i=0; i
}
System.out.println("Cost : "+cost);
System.out.println();
return cost;
}
}
BFS
public class NovFifth {
public static void main(String args[]){
int a = 10;
int b = 100;
String inputOperation1 = "*2";
String inputOperation2 = "*3";
String inputOperation3 = "+1";
char[] operations1 = inputOperation1.toCharArray();
char[] operations2 = inputOperation2.toCharArray();
char[] operations3 = inputOperation3.toCharArray();
char operator1 = operations1[0];
int operand1 = Character.getNumericValue(operations1[1]);
char operator2 = operations2[0];
int operand2 = Character.getNumericValue(operations2[1]);
char operator3 = operations3[0];
int operand3 = Character.getNumericValue(operations3[1]);
Operation[] operationArray = new Operation[3];
Operation Operation1 = new Operation(operator1, operand1);
Operation Operation2 = new Operation(operator2, operand2);
Operation Operation3 = new Operation(operator3, operand3);
operationArray[0] = Operation1;
operationArray[1] = Operation2;
operationArray[2] = Operation3;
Node startPoint = new Node();
Node start = new Node();
start.level = 0;
start.number = a;
startPoint = start;
Node endPoint = new Node();
endPoint = start;
Node currentNode = start;
int minimunLength = 0;
while(true){
boolean answerFlag = false;
int currentLevel = currentNode.level;
for(int i=0; i<3; i++){
Operation op = operationArray[i];
int answer = calc(currentNode.number, op.operator, op.operand);
if(answer == b){
answerFlag = true;
minimunLength = currentLevel + 1;
}else if(answer < b){
//Push Queue
Node node = new Node();
node.level = currentLevel + 1;
node.number = answer;
endPoint.next = node;
endPoint = endPoint.next;
}
}
if(answerFlag){
break;
}
//Pop Queue
currentNode = startPoint;
startPoint = startPoint.next;
}
printQueue(startPoint);
System.out.println("Answer : "+minimunLength);
}
public static int calc(int current, char operator, int operand){
int returnNum = 0;
if(operator == '*'){
returnNum = current * operand;
}else{
returnNum = current + operand;
}
return returnNum;
}
public static void printQueue(Node node){
int count = 0;
while(true){
//System.out.print(node.number+" ");
if(node.next == null){
break;
}else{
node = node.next;
count++;
}
}
}
}
class Operation{
public char operator;
public int operand;
public Operation(char operator, int operand){
this.operator = operator;
this.operand = operand;
}
}
class Node{
int number;
int level;
Node next;
}
public static void main(String args[]){
int a = 10;
int b = 100;
String inputOperation1 = "*2";
String inputOperation2 = "*3";
String inputOperation3 = "+1";
char[] operations1 = inputOperation1.toCharArray();
char[] operations2 = inputOperation2.toCharArray();
char[] operations3 = inputOperation3.toCharArray();
char operator1 = operations1[0];
int operand1 = Character.getNumericValue(operations1[1]);
char operator2 = operations2[0];
int operand2 = Character.getNumericValue(operations2[1]);
char operator3 = operations3[0];
int operand3 = Character.getNumericValue(operations3[1]);
Operation[] operationArray = new Operation[3];
Operation Operation1 = new Operation(operator1, operand1);
Operation Operation2 = new Operation(operator2, operand2);
Operation Operation3 = new Operation(operator3, operand3);
operationArray[0] = Operation1;
operationArray[1] = Operation2;
operationArray[2] = Operation3;
Node startPoint = new Node();
Node start = new Node();
start.level = 0;
start.number = a;
startPoint = start;
Node endPoint = new Node();
endPoint = start;
Node currentNode = start;
int minimunLength = 0;
while(true){
boolean answerFlag = false;
int currentLevel = currentNode.level;
for(int i=0; i<3; i++){
Operation op = operationArray[i];
int answer = calc(currentNode.number, op.operator, op.operand);
if(answer == b){
answerFlag = true;
minimunLength = currentLevel + 1;
}else if(answer < b){
//Push Queue
Node node = new Node();
node.level = currentLevel + 1;
node.number = answer;
endPoint.next = node;
endPoint = endPoint.next;
}
}
if(answerFlag){
break;
}
//Pop Queue
currentNode = startPoint;
startPoint = startPoint.next;
}
printQueue(startPoint);
System.out.println("Answer : "+minimunLength);
}
public static int calc(int current, char operator, int operand){
int returnNum = 0;
if(operator == '*'){
returnNum = current * operand;
}else{
returnNum = current + operand;
}
return returnNum;
}
public static void printQueue(Node node){
int count = 0;
while(true){
//System.out.print(node.number+" ");
if(node.next == null){
break;
}else{
node = node.next;
count++;
}
}
}
}
class Operation{
public char operator;
public int operand;
public Operation(char operator, int operand){
this.operator = operator;
this.operand = operand;
}
}
class Node{
int number;
int level;
Node next;
}
Thursday, October 27, 2016
청첩장 무료 샘플 제공 사이트 소개
카드마켓 (http://www.card-market.co.kr/)
- 다른 청첩장 제공 사이트가 배송비를 요구하는데 비해 무료로 샘플을 제공한다는 점에저 장점 (From&To, http://www.wfromnto.co.kr/ 의 경우 샘플 신청을 하였으나 2,500원 배송비 지불)
- 카드마켓이 From&To에비해 |1~20,000원 정도 비싸기는 하지만 청첩장 퀄리티나 완성도,추가 서비스(액자, 할인 쿠폰 제공, 추가 샘플 제공, 모바일 무료 청첩장 등) 등 다른 모든 면에서 월등히 앞선다고 판단됨.
카드마켓에서 무료로 제공된 샘플 청첩장
Thursday, October 20, 2016
DFS Example
public class DFSExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] conn = { { 0, 1, 0, 1, 0, 0, 0, 0, 1 }, // 0
{ 0, 0, 0, 0, 0, 0, 0, 1, 0 }, // 1
{ 0, 0, 0, 0, 0, 1, 0, 0, 0 }, // 2
{ 0, 0, 1, 0, 1, 0, 0, 0, 0 }, // 3
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 4
{ 0, 0, 0, 0, 0, 0, 1, 0, 0 }, // 5
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 6
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 7
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 } };// 8
boolean[] visited = new boolean[conn.length];
int v = 0;
DFS(conn, visited, v);
}
public static void DFS(int[][] conn, boolean[] visited, int v){
visited[v] = true;
System.out.println("nextNode : "+v);
for(int i = 0; i < visited.length; i++){
if(conn[v][i] > 0 && !visited[i]){
DFS(conn, visited, i);
}
}
}
}
BFS Exmaple
import java.util.LinkedList;
import java.util.Queue;
public class BFSExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] conn = { { 0, 1, 0, 1, 0, 0, 0, 0, 1 }, // 0
{ 1, 0, 0, 0, 0, 0, 0, 1, 0 }, // 1
{ 0, 0, 0, 1, 0, 1, 0, 1, 0 }, // 2
{ 1, 0, 1, 0, 1, 0, 0, 0, 0 }, // 3
{ 0, 0, 0, 1, 0, 0, 0, 0, 1 }, // 4
{ 0, 0, 1, 0, 0, 0, 1, 0, 0 }, // 5
{ 0, 0, 0, 0, 0, 1, 0, 0, 0 }, // 6
{ 0, 1, 1, 0, 0, 0, 0, 0, 0 }, // 7
{ 1, 0, 0, 0, 1, 0, 0, 0, 0 } };// 8
BFS(conn);
}
public static void BFS(int[][] conn) {
Queue q = new LinkedList();
boolean[] visited = new boolean[conn.length];
for(int i = 0; i < visited.length; i++){
visited[i] = false;
}
q.add(0);
while(!q.isEmpty()){
int nextNode;
int i;
nextNode= (int) q.remove();
if(!visited[nextNode]){
visited[nextNode] = true;
System.out.println("nextNode = "+ nextNode);
for(i = 0; i < visited.length; i++){
if(conn[nextNode][i] > 0 && !visited[i]){
q.add(i);
}
}
}
}
}
}
import java.util.Queue;
public class BFSExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] conn = { { 0, 1, 0, 1, 0, 0, 0, 0, 1 }, // 0
{ 1, 0, 0, 0, 0, 0, 0, 1, 0 }, // 1
{ 0, 0, 0, 1, 0, 1, 0, 1, 0 }, // 2
{ 1, 0, 1, 0, 1, 0, 0, 0, 0 }, // 3
{ 0, 0, 0, 1, 0, 0, 0, 0, 1 }, // 4
{ 0, 0, 1, 0, 0, 0, 1, 0, 0 }, // 5
{ 0, 0, 0, 0, 0, 1, 0, 0, 0 }, // 6
{ 0, 1, 1, 0, 0, 0, 0, 0, 0 }, // 7
{ 1, 0, 0, 0, 1, 0, 0, 0, 0 } };// 8
BFS(conn);
}
public static void BFS(int[][] conn) {
Queue q = new LinkedList();
boolean[] visited = new boolean[conn.length];
for(int i = 0; i < visited.length; i++){
visited[i] = false;
}
q.add(0);
while(!q.isEmpty()){
int nextNode;
int i;
nextNode= (int) q.remove();
if(!visited[nextNode]){
visited[nextNode] = true;
System.out.println("nextNode = "+ nextNode);
for(i = 0; i < visited.length; i++){
if(conn[nextNode][i] > 0 && !visited[i]){
q.add(i);
}
}
}
}
}
}
Sunday, October 18, 2015
주사위
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 50 51 52 53 54 55 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int N1 = sc.nextInt(); int N2 = sc.nextInt(); int N3 = sc.nextInt(); int Size = N1 * N2 * N3; int[] answerArray = new int[Size]; int answerIdx = 0; for(int i=1; i<=N1; i++){ for(int j=1; j<=N2; j++){ for(int k=1; k<=N3; k++){ answerArray[answerIdx++] = i + j + k; } } } Arrays.sort(answerArray); int currentNum = answerArray[0]; int maxNum = answerArray[0]; int currentCnt = 1; int maxCnt = 1; for(int i=1; i<answerArray.length; i++){ if(currentNum != answerArray[i]){ if(maxCnt < currentCnt){ maxNum = currentNum; maxCnt = currentCnt; } currentNum = answerArray[i]; currentCnt = 1; }else{ currentCnt++; } } System.out.println(maxNum); } } |
수학귀신
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 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int K = sc.nextInt(); long[] zeroCntArray = new long[K+1]; long[] oneCntArray = new long[K+1]; int i = 0; zeroCntArray[i] = 0; oneCntArray[i++] = 0; zeroCntArray[i] = 0; oneCntArray[i++] = 1; if(K >= 2){ zeroCntArray[i] = 1; oneCntArray[i++] = 1; for(; i<K+1; i++){ zeroCntArray[i] = zeroCntArray[i-1] + zeroCntArray[i-2]; oneCntArray[i] = oneCntArray[i-1] + oneCntArray[i-2]; } } System.out.println(zeroCntArray[K]+" "+oneCntArray[K]); } } |
창고다각형
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 50 51 52 53 54 55 56 57 58 59 60 61 62 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[][] inputArray = new int[N][2]; for(int i=0; i<N; i++){ inputArray[i][0] = sc.nextInt(); inputArray[i][1] = sc.nextInt(); } sort(inputArray); int maxHeightIndex = 0; int maxHeight = inputArray[0][1]; for(int i=0; i<N; i++){ if(inputArray[i][1] > maxHeight){ maxHeightIndex = i; maxHeight = inputArray[i][1]; } } System.out.println(maxHeightIndex+" "+maxHeight); int currentHeight = inputArray[0][1]; for(int i=0;i<maxHeightIndex;i++){ } } static void sort(int[][] inputArray){ for(int i=0; i<inputArray.length - 1; i++){ for(int j=i; j<inputArray.length - 1; j++){ if(inputArray[j][0] > inputArray[j+1][0]){ int tempLocation = inputArray[j][1]; inputArray[j][1] = inputArray[j+1][1]; inputArray[j+1][1] = tempLocation; int tempHieght = inputArray[j][0]; inputArray[j][0] = inputArray[j+1][0]; inputArray[j+1][0] = tempHieght; } } } } } |
Saturday, October 17, 2015
주차요금
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 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int M = sc.nextInt(); int[] mList = new int[M]; for(int i=0; i<M; i++){ mList[i] = sc.nextInt(); } int total = 0; for(int i=0; i<M; i++){ int subTotal = 0; if(mList[i] < 10){ subTotal = 0; }else if(mList[i] >= 10 && mList[i] <= 30){ subTotal = 500; }else{ subTotal = 500 + (((mList[i] - 31)/10) + 1) * 300; } if(subTotal > 50000){ subTotal = 50000; } total += subTotal; } System.out.println(total); } } |
잃어버린 페이지
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 50 51 52 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int P = sc.nextInt(); int pageArrayRow = N/4; int[][] pageArray = new int[pageArrayRow][4]; int number = 1; for(int i=0; i<pageArrayRow; i++){ pageArray[i][0] = number++; pageArray[i][1] = number++; } for(int i=N/4-1; i>=0; i--){ pageArray[i][2] = number++; pageArray[i][3] = number++; } int index = 0; if(P > N/2){ if(P%2 == 0){ index = Math.abs((P-N/2)/2 - (N/4)); }else{ index = Math.abs((P-N/2)/2 - (N/4-1)); } }else{ index = (P-1)/2; } int[] answer = new int[3]; int answerIndex = 0; for(int i=0; i<4; i++){ if(pageArray[index][i] != P){ answer[answerIndex++]= pageArray[index][i]; } } System.out.println(answer[0]+" "+answer[1]+" "+answer[2]); } } |
폭탄돌리기
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 50 51 52 53 54 55 56 57 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int K = sc.nextInt(); int N = sc.nextInt(); int[] timeArray = new int[N]; char[] answerArray = new char[N]; for(int i=0 ; i<N ; i++){ timeArray[i] = sc.nextInt(); String s = sc.next(); answerArray[i] = s.charAt(0); } int timeAnswerIdx = 0; int timer = 0; int i = K; for(;;){ if(timeAnswerIdx > N-1){ break; } int currentTime = timeArray[timeAnswerIdx]; char currentAnswer = answerArray[timeAnswerIdx]; timeAnswerIdx++; timer += currentTime; if(timer > 210){ break; } if(currentAnswer =='T'){ i++; } if(i == 9){ i = 1; } } System.out.println(i); } } |
할부
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 | import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int B = sc.nextInt(); int Quotient = B / (N-1); int min = 0; int max = 0; if(B % (N-1) == 0){ min = Quotient-1+B; max = Quotient+B; }else{ min = Quotient+B; max = Quotient+B; } System.out.println(min+" "+max); } } |
Subscribe to:
Posts (Atom)
