구의 일부분이 되는 붉게 표시한 원을 구할 때

원의 반지름은 rcos(t)

중심점으로부터의 높이는 rsin(t)



point.z = r*sin(t);

point.x = r*cos(t)*cos(경도);  

point.y = r*cos(t)*sin(경도);


z값은 중심점으로부터의 높이로 두고

x와 y값은 반지름( rcos(t) )에 경도의 코사인값과 사인값을 취하여 곱한다.


















#include <stdio.h>
#include <stdlib.h>

//void solution();

int main(void)
{
int testSet;
int heads;
int *arr, *check;
int j,i, imax, imin;
int position;
int answer;

scanf("%d",&testSet);


for(j=0;j<testSet;j++) {

scanf("%d",&heads);

arr = (int*)malloc(heads*sizeof(int));
check = (int*)calloc(heads, sizeof(int));

for(i=0;i<heads;i++)
scanf("%d",&arr[i]);

position = 0; 
while(position<heads) {
imax = position;
for(i=position;i<heads;i++) 
if(arr[i]-1 >= i-position && arr[i]>=arr[position]) {
imax = i;
};
++check[imax];
if(imax == heads-1) break;
if(imax!=position)
position = imax;
else position += arr[position];
if(arr[position]+position>heads) break;
}


answer = 0;
for(i=0; i<heads; i++) 
// if(check[i])  ++answer;
printf("%-2d",check[i]);

free(arr);
free(check);
printf("%d\n",answer);
}

return 0;
}

+ Recent posts