SCPC

SCPC 예제 #Day 1#

2017. 12. 27. 23:34

< 문 제 > -------------------------------------------------------------------------------------------------



< 소스코드 >------------------------------------------------------------------------------------------------


#include <stdio.h>

#include <stdlib.h>

#include <time.h>


int main(void)

{

int T, test_case;

int candidate,stemp,number;

clock_t start_point, end_point;

srand((int)time(NULL));

setbuf(stdout, NULL);


printf("테스트 케이스 개수(5개 이하) : ");

scanf("%d", &T);

if(T>5)

exit(1);

start_point = clock();

for(test_case = 0; test_case < T; test_case++)

{

printf("응시자수 입력 :");

scanf("%d",&candidate);

int* score=(int*)malloc(sizeof(int) * candidate);

int* score_temp=(int*)malloc(sizeof(int) * candidate);

for (int i = 0; i < candidate; i++)

score[i]=0;


int round = rand() % 7;

if(round == 0)

round = 2 + rand()% 5;

if(round == 1)

round = 2 + rand()% 4;


printf("\n총 라운드수 : %d\n",round);


for (int times=1; times < round; times++)

{

printf("%d라운드\n",times);

for (int temp=0; temp < candidate; temp++)  // 각 라운드마다 응시자들이 받는 N~1점(중복없이)까지의 점수 설정 알고리즘

{

score_temp[temp] = rand() % candidate+1;

for(int i=0; i <= temp; i++)

{

for (int j=0; j <= i; j++)

{

if(i!=j)

{

if(score_temp[i] == score_temp[j])

{

temp -= temp;

i -= i;

j -= j;

}

}

}

}

}

for (int k = 0; k < candidate; k++)

score[k] += score_temp[k];

}


for (int sort=0; sort<candidate; sort++) // 응시자들의 점수를 오름차순으로 정렬알고리즘

{

for (int sort_t=0; sort_t < sort; sort_t++)

{

if(score[sort] > score[sort_t])

{

stemp = score[sort_t];

score[sort_t] = score[sort];

score[sort] = stemp;

}

}

}

printf("<마지막 라운드 직전 종합점수>\n");

for (int i = 0; i < candidate; i++)

printf("응시자 %d번 점수 : %d\n",i+1,score[i]);


number = 0;


for (int i = 0; i < candidate; i++) // 우승가능성이 있는 응시자들을 검색하는 알고리즘

{

if(score[0]+1 > score[i] + candidate)

break;

number++;

}


printf("\n\nCase #%d\n",test_case+1);

printf("우승가능성 응시자수 : %d\n\n",number);

}

end_point = clock();

printf("실행시간 : %f sec\n", ((double)(end_point-start_point)/CLOCKS_PER_SEC));


return 0;

}


< 실 행 >-----------------------------------------------------------------------------------------------------


-------------------------------------------------------------------------------------------------------------


'Programming > Algorithm' 카테고리의 다른 글

백준 알고리즘 문제(C++) #1000  (0) 2020.06.30

+ Recent posts