회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
반례 경우 찾습니다
2108번 - 통계학
watermelon8338
1년 전
0
웬만한 반례글 봐도 문제 없어서 올립니다.
#include <stdio.h> #include <stdlib.h> int round(double value) // 반올림 함수 { if(value<0) { return (int)(value-0.5); } else return (int)(value+0.5); } void merge(int *list,int s,int e,int mid) // 머지소트 { int* temp=(int*)malloc(4*(e-s)); int left=s,right=mid,temp_point=0; while(left<mid&&right<e) { if(list[left]<list[right]) { temp[temp_point]=list[left]; temp_point++; left++; } else { temp[temp_point]=list[right]; temp_point++; right++; } } while(left<mid) { temp[temp_point]=list[left]; temp_point++; left++; } while(right<e) { temp[temp_point]=list[right]; temp_point++; right++; } temp_point--; for(int k=temp_point; k>=0; k--) { list[s+k]=temp[k]; } free(temp); } void merge_sort(int*list,int s,int e) { if(s<e-1) { int mid= (s+e)/2; merge_sort(list,s,mid); merge_sort(list,mid,e); merge(list,s,e,mid); } } int main() { int n,temp,sum=0; scanf("%d",&n); int* list=(int*)malloc(4*n); for(int i=0; i<n; i++) { scanf(" %d",&temp); list[i]=temp; sum+=temp; } merge_sort(list,0,n); //choi - 루프 두 번 돌려서 두번째 최빈값찾기 int choi=list[0],count=1,max=1; for(int i=1; i<n; i++) { if(list[i]==list[i-1]) { count++; if(count>max) { choi=list[i]; max=count; } } else { count=1; } } for(int i=max;i<n;i++) { if(list[i]==list[i-1]) { count++; if(count==max&&choi!=list[i]) { choi=list[i]; break; } } else { count=1; if(count==max&&choi!=list[i]) { choi=list[i]; break; } } } if(n==1) { printf("%d\n%d\n%d\n%d",temp,temp,temp,0); } else { printf("%d\n%d\n%d\n%d",round((double)sum/n),list[(n+1)/2-1],choi,list[n-1]-list[0]); } free(list); }
dldyddlwl
1년 전
1
.
int choi=list[0],count=1,max=1; for(int i=1; i<n; i++) { if(list[i]==list[i-1]) { count++; if(count>max) { choi=list[i]; max=count; } } else { count=1; } } // count 초기화해주세요 for(int i=max;i<n;i++) { if(list[i]==list[i-1]) { count++; if(count==max&&choi!=list[i]) { choi=list[i]; break; } } else { count=1; if(count==max&&choi!=list[i]) { choi=list[i]; break; } } }
watermelon8338
1년 전
0
감사합니다
댓글을 작성하려면
로그인
해야 합니다.
watermelon8338 1년 전
웬만한 반례글 봐도 문제 없어서 올립니다.