꼬반 Blog

잊지 말아야 할 것.

세월호. 절대 우리가 잊지 말아야 할..

Read More

TSP - DFS

#include #include #include #include using namespace std; #define MAX 150 typedef struct Vertex* Vertex_Pointer; int Top = -1; struct Vertex { double x, y; double distance; int dept; int check[10]; Vertex_Pointer link; }; Vertex_Pointer Stack[MAX]; void Stack_push(Vertex_Pointer input) { if(Top == MAX - 1){ cout

Read More

TSP - Recursion

#include #include #include #include #include #include #define MAX 150 int *xpoint; int *ypoint; int vertex, s = 1; int point, depth = 0; float during_t; LARGE_INTEGER frequency, start_t, finish_t; void greedy(int a); int way(int b); void main() { int i = 0; int txp = 0, typ = 0; printf("number of vertexies ? : "); scanf("%d", &vertex); xpoint = (int*)malloc(vertex); ypoint = (int*)malloc(vertex)..

Read More

TSP - Greedy

#include #include #include #include #include #include #define MAX 150 int *xpoint; int *ypoint; int vertex, s = 1; int point, depth = 0; float during_t; LARGE_INTEGER frequency, start_t, finish_t; void greedy(int a); int way(int b); void main() { int i = 0; int txp = 0, typ = 0; printf("number of vertexies ? : "); scanf("%d", &vertex); xpoint = (int*)malloc(vertex); ypoint = (int*)malloc(vertex)..

Read More

간단 그리드 알고리즘

#include #include #define CA 500 #define CB 100 #define CC 50 #define CD 10 #define CLK_TCK 1000 void count(int c, int b); void main() { long start, stop; float time; int charge, bcharge; printf("금액 설정 : "); scanf("%d",&charge); printf("사용할 금액은 : "); scanf("%d",&bcharge); start = GetTickCount(); count(charge, bcharge); stop = GetTickCount(); time = (float)(stop-start)/CLK_TCK; printf("TIME : %f ..

Read More

그리드 실행시간 구하기 포함버젼.

#include #include #define MAX 150 #define CA 500 #define CB 100 #define CC 50 #define CD 10 #define CLK_TCK 1000 int queue1[MAX]; // 잔액 int queue2[MAX]; // 500원 int queue3[MAX]; // 100원 int queue4[MAX]; // 50원 int queue5[MAX]; // 10원 void add2(int x2, int y2); void add3(int x3, int y3); void add4(int x4, int y4); void add5(int x5, int y5); void del(); void greedy(int c1, int c2); void makenode()..

Read More

잊지 말아야 할 것.


세월호. 절대 우리가 잊지 말아야 할..


반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post

TSP - DFS

#include <iostream>
#include <cmath>
#include <time.h>
#include <windows.h>
using namespace std;

#define MAX 150

typedef struct Vertex* Vertex_Pointer;

int Top = -1;

struct Vertex
{
double x, y;
double distance;
int dept;
int check[10];
Vertex_Pointer link;
};

Vertex_Pointer Stack[MAX];

void Stack_push(Vertex_Pointer input)
{
if(Top == MAX - 1){
cout<<"스택이 가득찼습니다.\n"<<endl;

return;
}

Stack[++Top] = input;
}

Vertex_Pointer Stack_pop()
{
if(Top < 0){
cout<<"스택이 비었습니다.\n"<<endl;

exit(0);
}

return Stack[Top--];
}

Vertex_Pointer vertex_Create(Vertex, int index);
Vertex_Pointer vertex_Create();

Vertex_Pointer vertex_copy(Vertex_Pointer);

void print_path(Vertex_Pointer);
void travel(Vertex_Pointer, Vertex_Pointer);

Vertex P[10] = {{2,8}, {4,5}, {7,3}, {11,17}, {5,13}, {12,7}, {1,6}, {7,2}, {11,3}, {13,6}};

double compare = 999;
Vertex_Pointer result;

float during_t;
LARGE_INTEGER frequency, start_t, finish_t;

void main()
Vertex_Pointer ptr,tmp;

Stack_push(vertex_Create(P[0],0));
srand(time(NULL));
    QueryPerformanceFrequency( &frequency );

QueryPerformanceCounter( &start_t );

while(Top > -1)
{
ptr = Stack_pop();
tmp = vertex_copy(ptr);

travel(ptr, tmp);
}

QueryPerformanceCounter( &finish_t );  // get finish time..

cout<<"최단 경로 : "<<P[0].x<<", "<<P[0].y;
print_path(result);
cout<<" - > "<<P[0].x<<", "<<P[0].y;
cout<<" 최단 거리 : "<<compare<<endl;

during_t = ( (float)finish_t.QuadPart - (float)start_t.QuadPart ) / (float)frequency.QuadPart * (float)1000.0;
if( during_t < 1000.) // print millisecond
        printf("* During Time .. %.4f(msec)\n", during_t);
    else if( during_t/1000. < 60.) // print second
        printf("* During Time .. %.1f(sec)\n", during_t/1000);
    else if( during_t/60000. < 60.) // print min
        printf("* During Time .. %.0f(min)\n", during_t/60000.);
    else  //print hour
        printf("* During Time .. %.0f(hour)\n", during_t/3600000.);

return;
}

void travel(Vertex_Pointer pp, Vertex_Pointer bkup)
{
for(int i = 0; i < 10; i++)
{
if(pp->check[i] == false)
{
pp->check[i] = true;
pp->x = P[i].x; 
pp->y = P[i].y;
pp->dept++;
pp->distance += sqrt(pow(pp->x - bkup->x,2) + pow(pp->y - bkup->y, 2));
pp->link = bkup;
Stack_push(pp);
if(pp->dept == 10)
{
if(compare > pp->distance + sqrt(pow(pp->x - P[0].x,2) + pow(pp->y - P[0].y, 2)))
compare = pp->distance + sqrt(pow(pp->x - P[0].x,2) + pow(pp->y - P[0].y, 2));
result = vertex_copy(pp);
cout<<"최단 경로 : "<<P[0].x<<", "<<P[0].y;
print_path(result);
cout<<" - > "<<P[0].x<<", "<<P[0].y;
cout<<" 최단 거리 : "<<compare<<endl;
}
if(compare <= pp->distance + sqrt(pow(pp->x - P[0].x,2) + pow(pp->y - P[0].y, 2)))
{
result = vertex_copy(pp);
cout<<" 경로 : "<<P[0].x<<", "<<P[0].y;
print_path(result);
cout<<" - > "<<P[0].x<<", "<<P[0].y<<endl;
}
}
}
pp = vertex_copy(bkup);
}
}

Vertex_Pointer vertex_Create(Vertex p, int index)
{
Vertex_Pointer tmp = new struct Vertex;

tmp->x = p.x;
tmp->y = p.y;
tmp->distance = 0;
tmp->link = 0;
tmp->dept = 1;
for(int i = 0 ; i < 10 ; i++)
tmp->check[i] = false;

tmp->check[index] = true;

return tmp;
}

Vertex_Pointer vertex_Create()
{
Vertex_Pointer tmp = new struct Vertex;

tmp->x = 0;
tmp->y = 0;
tmp->distance = 0;
tmp->link;
tmp->dept = 1;
for(int i = 0 ; i < 10 ; i++)
tmp->check[i] = false;

return tmp;
}

Vertex_Pointer vertex_copy(Vertex_Pointer ori)
{
Vertex_Pointer copy = vertex_Create();

copy->x = ori->x;
copy->y = ori->y;
copy->distance = ori->distance;
copy->link = ori->link;
copy->dept = ori->dept;
for(int i = 0 ; i < 10 ; i++)
copy->check[i] = ori->check[i];

return copy;
}

void print_path(Vertex_Pointer ptr)
{
if(ptr->link != NULL)
print_path(ptr->link);

if(ptr->link == NULL) return;
cout<<" -> "<<ptr->x<<", "<<ptr->y;
}

반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post

TSP - Recursion

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <memory.h>
#include <windows.h>
#include <time.h>

#define MAX 150

int *xpoint;
int *ypoint;
int vertex, s = 1;
int point, depth = 0;

float during_t;
LARGE_INTEGER frequency, start_t, finish_t;

void greedy(int a);
int way(int b);

void main()
{
int i = 0;
int txp = 0, typ = 0;
printf("number of vertexies ? : ");
scanf("%d", &vertex);

xpoint = (int*)malloc(vertex);
ypoint = (int*)malloc(vertex);
xpoint[0] = 0;
ypoint[0] = 0;

for(i = 1; i < vertex; i++)
{
printf("vertex_%d point ? ex)17 2 ex1)xpoint ypoint : ", i);
scanf("%d %d", &txp , &typ);
xpoint[i] = txp;
ypoint[i] = typ;
}
point = 0;
printf("포인트의 값: %d\n", point);

srand(time(NULL));
    QueryPerformanceFrequency( &frequency );
QueryPerformanceCounter( &start_t );

while(s)
{
greedy(point);
}

QueryPerformanceCounter( &finish_t );  // get finish time..
    during_t = ( (float)finish_t.QuadPart - (float)start_t.QuadPart ) / (float)frequency.QuadPart * (float)1000.0;
if( during_t < 1000.) // print millisecond
        printf("* During Time .. %.4f(msec)\n", during_t);
    else if( during_t/1000. < 60.) // print second
        printf("* During Time .. %.1f(sec)\n", during_t/1000);
    else if( during_t/60000. < 60.) // print min
        printf("* During Time .. %.0f(min)\n", during_t/60000.);
    else  //print hour
        printf("* During Time .. %.0f(hour)\n", during_t/3600000.);

xpoint=NULL;
ypoint=NULL;
free(xpoint);
free(ypoint);
}

void greedy(int a)
{
int t1;
if(depth+1 == vertex)
{
s = 0;
} else {
t1 = way(point);
printf("이동할 vertex는 : %d\n", point);
depth++;
greedy(point);
}
}

int way(int b)
{
int temp[MAX] = {0};
int t[MAX] = {0};
int i;
int x, y;
int t1;
x = xpoint[b];
y = ypoint[b];
xpoint[b] = 0;
ypoint[b] = 0;
for(i = 1; i < vertex; i++)
{
if((xpoint[i] != 0)&&(ypoint[i] !=0))
{
temp[i] = (int)(pow((xpoint[i] - x) ,2) + pow((ypoint[i] - y), 2));
temp[i] = (int)(sqrt(temp[i]));
}
else
{
continue;
}
}

for(i = 0; i < vertex; i++)
{
t[i] = temp[i];
}

for(i = 0; i < vertex; i++)
{
if(t[i] != 0)
{
t1 = t[i];
break;
}
}

for(i = 0; i < vertex; i++)
{
if(temp[i] != 0)
{
if(temp[i] < t1)
{
t1 = temp[i];
}
else
{
t1 = t1;
}
}
}

printf("\n최소 거리 : %d ", t1);
for(i = 0; i < vertex; i++)
{
if(temp[i] == t1)
{
point = i;
}
}
return t1;
}
반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post

TSP - Greedy

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <memory.h>
#include <windows.h>
#include <time.h>

#define MAX 150

int *xpoint;
int *ypoint;
int vertex, s = 1;
int point, depth = 0;

float during_t;
LARGE_INTEGER frequency, start_t, finish_t;

void greedy(int a);
int way(int b);

void main()
{
int i = 0;
int txp = 0, typ = 0;
printf("number of vertexies ? : ");
scanf("%d", &vertex);

xpoint = (int*)malloc(vertex);
ypoint = (int*)malloc(vertex);
xpoint[0] = 0;
ypoint[0] = 0;

for(i = 1; i < vertex; i++)
{
printf("vertex_%d point ? ex)17 2 ex1)xpoint ypoint : ", i);
scanf("%d %d", &txp , &typ);
xpoint[i] = txp;
ypoint[i] = typ;
}
point = 0;
printf("포인트의 값: %d\n", point);

srand(time(NULL));
    QueryPerformanceFrequency( &frequency );
QueryPerformanceCounter( &start_t );

while(s)
{
greedy(point);
}

QueryPerformanceCounter( &finish_t );  // get finish time..
    during_t = ( (float)finish_t.QuadPart - (float)start_t.QuadPart ) / (float)frequency.QuadPart * (float)1000.0;
if( during_t < 1000.) // print millisecond
        printf("* During Time .. %.4f(msec)\n", during_t);
    else if( during_t/1000. < 60.) // print second
        printf("* During Time .. %.1f(sec)\n", during_t/1000);
    else if( during_t/60000. < 60.) // print min
        printf("* During Time .. %.0f(min)\n", during_t/60000.);
    else  //print hour
        printf("* During Time .. %.0f(hour)\n", during_t/3600000.);

xpoint=NULL;
ypoint=NULL;
free(xpoint);
free(ypoint);
}

void greedy(int a)
{
int t1;
if(depth+1 == vertex)
{
s = 0;
} else {
t1 = way(point);
printf("이동할 vertex는 : %d\n", point);
depth++;
greedy(point);
}
}

int way(int b)
{
int temp[MAX] = {0};
int t[MAX] = {0};
int i;
int x, y;
int t1;
x = xpoint[b];
y = ypoint[b];
xpoint[b] = 0;
ypoint[b] = 0;
for(i = 1; i < vertex; i++)
{
if((xpoint[i] != 0)&&(ypoint[i] !=0))
{
temp[i] = (int)(pow((xpoint[i] - x) ,2) + pow((ypoint[i] - y), 2));
temp[i] = (int)(sqrt(temp[i]));
}
else
{
continue;
}
}

for(i = 0; i < vertex; i++)
{
t[i] = temp[i];
}

for(i = 0; i < vertex; i++)
{
if(t[i] != 0)
{
t1 = t[i];
break;
}
}

for(i = 0; i < vertex; i++)
{
if(temp[i] != 0)
{
if(temp[i] < t1)
{
t1 = temp[i];
}
else
{
t1 = t1;
}
}
}

printf("\n최소 거리 : %d ", t1);
for(i = 0; i < vertex; i++)
{
if(temp[i] == t1)
{
point = i;
}
}
return t1;
}
반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post

간단 그리드 알고리즘


#include <stdio.h>
#include <windows.h>

#define CA 500
#define CB 100
#define CC 50
#define CD 10
#define CLK_TCK 1000

void count(int c, int b);

void main()
{
 long start, stop;
 float time;

 int charge, bcharge;

 printf("금액 설정 : ");
 scanf("%d",&charge);
 printf("사용할 금액은 : ");
 scanf("%d",&bcharge);
 start = GetTickCount();
 count(charge, bcharge);
 stop = GetTickCount();
 
 time = (float)(stop-start)/CLK_TCK;
 
 printf("TIME : %f s\n", time);
}


void count(int c, int b)
{
 int t[4] = {0, 0, 0, 0};
 int i = 0;
 int cg = c - b;
 
 printf("거스름돈은 %d원 입니다.\n",cg);
 
 while(cg > 0)
 {
  if(cg >= CA)
  {
   cg = cg - CA;
   t[0] = t[0]++;
  }
  else if(cg >= CB)
  {
   cg = cg - CB;
   t[1] = t[1]++;
  }else if(cg >= CC)
  {
   cg = cg - CC;
   t[2] = t[2]++;
  }
  else if(cg >= CD)
  {
   cg = cg - CD;
   t[3] = t[3]++;
  }
 }
 printf("\n거스름돈 동전의 갯수는\n500원 %d개, 100원 %d개, 50원 %d개, 10원 %d개 입니다.\n",t[0],t[1],t[2],t[3]);
}

반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post

그리드 실행시간 구하기 포함버젼.



#include <stdio.h>
#include <windows.h>

#define MAX 150
#define CA 500
#define CB 100
#define CC 50
#define CD 10
#define CLK_TCK 1000

int queue1[MAX]; // 잔액
int queue2[MAX]; // 500원
int queue3[MAX]; // 100원
int queue4[MAX]; // 50원
int queue5[MAX]; // 10원

void add2(int x2, int y2);
void add3(int x3, int y3);
void add4(int x4, int y4);
void add5(int x5, int y5);
void del();

void greedy(int c1, int c2);
void makenode();
void print();
void count();

int front1 = 0, rear1 = 0;
int front2 = 0, rear2 = 0;
int front3 = 0, rear3 = 0;
int front4 = 0, rear4 = 0;
int front5 = 0, rear5 = 0;

int cnt = 0;
int tf2, tf3, tf4, tf5;

void main()
{
 long start, stop;
 float time;
 
 int in, in2;
 in = 0;
 in2 = 0;
 
 printf("금액을 넣어주세요 : ");
 scanf("%d",&in);
 printf("\n사용한 금액은 얼마인가요 : ");
 scanf("%d", &in2);
 
 start = GetTickCount();
 greedy(in, in2);
 stop = GetTickCount();
 
 time = (float)(stop-start)/CLK_TCK;
 
 printf("TIME : %f s\n", time);
}

void greedy(int c1, int c2)
{
 int charge = c1 - c2;
 
 queue1[0] = charge;
 printf("잔액 설정 : %d \n",queue1[0]);

 while(1)
 {
  if(cnt == 1)
  {
   count();
   printf("잔액 %d원의 거스름돈 동전의 갯수는 \n500원 : %d개 , 100원 : %d개, 50원 : %d개, 10원 : %d개 입니다.\n", queue1[0], tf2, tf3, tf4, tf5);
   break;
  }
  makenode();
  //print();
  del();
 }
}


void makenode()
{
 int t, t2, t3, t4, t5;
 
 if(queue1[front1] == 0)
 {
  cnt++;
 }
  
 if(queue1[front1] > 0)
 {
  if(queue1[front1] >= CA)
  {
   t = queue1[front1] - CA;
   t2 = 1;
   add2(t, t2);
  }
 
  if(queue1[front1] >= CB)
  {
   t = queue1[front1] - CB;
   t3 = 1;
   add3(t, t3);
  }
 
  if(queue1[front1] >= CC)
  {
   t = queue1[front1] - CC;
   t4 = 1;
   add4(t, t4);
  }
 
  if(queue1[front1] >= CD)
  {
   t = queue1[front1] - CD;
   t5 = 1;
   add5(t, t5);
  }
 }
}

void add2(int x2, int y2)
{
 if(rear1 == MAX) rear1 = 0;
 queue1[++rear1] = x2;
 if(rear2 == MAX) rear2 = 0;
 if(y2 == 1)
 {
  queue2[rear2] = y2;
 }else queue2[rear2] = 0;
 rear2++;
}

void add3(int x3, int y3)
{
 if(rear1 == MAX) rear1 = 0;
 queue1[++rear1] = x3;
 if(rear3 == MAX) rear3 = 0;
 if(y3 == 1)
 {
  queue3[rear3] = y3;
 }else queue3[rear3] = 0;
 rear3++;
}

void add4(int x4, int y4)

 if(rear1 == MAX) rear1 = 0;
 queue1[++rear1] = x4;
 if(rear4 == MAX) rear4 = 0;
 if(y4 == 1)
 {
  queue4[rear4] = y4;
 }else queue4[rear4] = 0;
 rear4++;
}

void add5(int x5, int y5)
{
 if(rear1 == MAX) rear1 = 0;
 queue1[++rear1] = x5;
 if(rear5 == MAX) rear5 = 0;
 if(y5 == 1)
 {
 queue2[rear5] = y5;
 }else queue5[rear5] = 0;
 rear5++;
}


void del()
{
 if(front1 == MAX) front1 = 0;
 front1++;
}


void print()
{
 printf("잔액 : %d \n",queue1[front1]);
}

void count()
{
 int t[4] = {0, 0, 0, 0};
 int i = 0;
 int cg = queue1[0];

 while(cg > 0)
 {
  if(cg >= CA)
  {
   cg = cg - CA;
   t[0] = t[0]++;
  }
  else if(cg >= CB)
  {
   cg = cg - CB;
   t[1] = t[1]++;
  }else if(cg >= CC)
  {
   cg = cg - CC;
   t[2] = t[2]++;
  }
  else if(cg >= CD)
  {
   cg = cg - CD;
   t[3] = t[3]++;
  }
 }
 tf2 = t[0];
 tf3 = t[1];
 tf4 = t[2];
 tf5 = t[3];
}

반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post