개미 문제(틀림)
#include<stdio.h>
#include<math.h>
int main()
{
FILE *in;
FILE *out;
int ant_max,ant_min;
int table;
int size,ant;
int j,i;
int arr[1000]={0,}; //위치저장
int p; //개미들 위치입력
int min,c_min; //짧은시간, 중간
int temp1,temp2,temp3;
int t4,t5;
int center;
in=fopen("in.txt","r");
out=fopen("out.txt","w");
fscanf(in,"%d",&table);
for(i=0;i<table;++i)
{
while(!feof(in))
{
fscanf(in,"%d %d", &size,&ant);
printf("%d %d\n",size,ant);
center=size/2;
printf("중앙 %d\n",center);
c_min=size;
min=size;
for(j=0;j<ant;j++)
{
t4=t5=temp1=temp2=temp3=0; //초기화
fscanf(in,"%d",&p);
arr[j]=p;
printf("%d\n",arr[j]);
//////////////////////////////////
//작은개미 위치
temp1=arr[j]; //0<-개미거리
temp2=size-arr[j]; //반대쪽 거리
if(temp1<temp2)
temp3=temp1;
else
temp3=temp2;
if(min>temp3)
min=temp3; //작은개미 위치
///////////////////////////////////
//중간개미 위치
temp1=abs(center-arr[j]); //중간거리 비교
if(c_min>temp1) //가까운에 저장
c_min=temp1;
}
//짧은시간 = 길이 - 중간개미
//긴시간 = 길이 - 작은개미
printf("%d %d\n",center-c_min,size-min);
fprintf(out,"%d %d\n",center-c_min,size-min);
}
}
fclose(in);
fclose(out);
}