#include<stdio.h>#include<math.h>int main(){
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;
scanf("%d",&table);
for(i=0;i<table;++i) { scanf("%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; //초기화
scanf("%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);
}
소스코드 공개 설정은 그 문제는 맞힌 사람들이 볼 수 있는지 여부를 설정하는 것입니다. 못 맞힌 사람은 공개 여부에 관계 없이 읽기가 불가능합니다.
예제 샘플이라도 더 있었으면 좋겠는데 ㅠ...
댓글을 작성하려면 로그인해야 합니다.
junja 9년 전
#include<stdio.h>
#include<math.h>
int main()
{
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;
scanf("%d",&table);
for(i=0;i<table;++i)
{
scanf("%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; //초기화
scanf("%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);
}
}
예제는 나오는데 계속 틀렸다고 나오네요 ㅠㅠ.. 감이 안오네요...;;