Skip to content

Instantly share code, notes, and snippets.

@s-yoshiki
Created October 16, 2015 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-yoshiki/47ba13a2eac989752b23 to your computer and use it in GitHub Desktop.
Save s-yoshiki/47ba13a2eac989752b23 to your computer and use it in GitHub Desktop.
report tan
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#define N 15
/*
struct point{
int x;
int y;
};
struct point p[N];
int area(struct point q1,struct point q2,struct point q3){
return ((q1.x - q3.x)*(q2.y-q3.y)+(q2.x-q3.x)*(q3.y-q1.y));
}
void quicksort(int first,int last){
int i,j,somewhere;
struct point pivot,temp;
if(first<last){
somewhere = (first + last)/2;
pivot.x = p[somewhere].x;
pivot.y = p[somewhere].y;
i = first;
j = last;
do{
//while(atan(p[i].y/p[i].x) < atan(pivot.y/pivot.x))i++;
//while(atan(p[i].y/p[i].x) > atan(pivot.y/pivot.x))j--;
while(area(p[0],pivot,p[i])<0)i++;
while(area(p[0],pivot,p[j])>0)j--;
if(i<=j){
temp=p[i];
p[i]=p[j];
p[j]=temp;
i++;
j--;
}
}while(i<=j);
quicksort(first,j);
quicksort(i,last);
}
}
int GrahamScan(){
int i, top ,min;
struct point temp;
min = 0;
for(i=0;i<N;i++){
if(p[i].y<p[min].y || p[i].y==p[min].y && p[i].x > p[min].x){
min = i;
}
}
temp = p[0];
p[0]=p[min];
p[min]=temp;
quicksort(1,N-1);
top = 1;
for(i=2;i<N;i++){
while(area(p[top-1],p[top],p[i])<=0)
top--;
top++;
temp = p[top];
p[top] = p[i];
p[i] = temp;
}
return (top+1);
}
int main(){
int result;
int array1[] = {
2,0,14,0,14,5,2,5,3,4,3,1,5,1,7,1,9,1,11,1,13,1,13,3,13,4,11,4,9,4
};
for(int i=0;i<15;i++){
printf("\nx%d:",array1[i]);
p[i].x = array1[i];
printf("\ny%d:",array1[i]);
p[i].y = array1[i+1];
}
result = GrahamScan();
char xx;
printf("%d\n",result);
scanf_s("%c",&xx);
}*/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
struct point{int x,y;};
struct point p[N];
int area(struct point q1,struct point q2,struct point q3)
{
return((q1.x-q3.x)*(q2.y-q3.y)+(q2.x-q3.x)*(q3.y-q1.y));
}
void quicksort(int first,int last)
{
int i,j,somewhere;
struct point pivot,temp;
if(first<last)
{
somewhere=(first+last)/2;
pivot=p[somewhere];
i=first;
j=last;
do{
while(area(p[0],pivot,p[i])<0)i++;
while(area(p[0],pivot,p[j])>0)j--;
//while(atan(p[i].y/p[i].x) < atan(pivot.y/pivot.x))i++;
//while(atan(p[i].y/p[i].x) > atan(pivot.y/pivot.x))j--;
if(i<=j)
{temp=p[i];p[i]=p[j];p[j]=temp;
i++;j--;
}
}while(i<=j);
quicksort(first,j);
quicksort(i,last);
}
}
int GrahamScan()
{
int i,top,min;
struct point temp;
min=0;
for(i=1;i<N;i++)
if(p[i].y<p[min].y||p[i].y==p[min].y&&p[i].x>p[min].x)
min=i;
temp=p[0];
p[0]=p[min];
p[min]=temp;
quicksort(1,N-1);
top=1;
for(i=2;i<N;i++)
{
while(area(p[top-1],p[top],p[i])<=0)
top--;
top++;
temp=p[top];
p[top]=p[i];
p[i]=temp;
}
return(top+1);
}
void main(void)
{
int i=0,k=0;
int array1[] = {
2,0,14,0,14,5,2,5,3,4,3,1,5,1,7,1,9,1,11,1,13,1,13,3,13,4,11,4,9,4
};
/*
for(i=0;i<N;i++){
printf("%dx:",i);
scanf_s("%d",&p[i].x);
printf("%dy:",i);
scanf("%d",&p[i].y);
}
*/
for(int i=0;i<15;i++){
printf("\nx:%d",array1[i]);
p[i].x = array1[i];
printf("\ny:%d",array1[i]);
p[i].y = array1[i+1];
}
k=GrahamScan();
printf("\nRESULT:%d",k);
char xx;
scanf_s("%c",&xx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment