회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
2%까지밖에 못가고 틀렸습니다 뜨는데 이유를 모르겠습니다ㅠㅠ
11286번 - 절댓값 힙
finn_02
3년 전
0
2%까지밖에 못가고 틀렸습니다 뜨는데 이유를 모르겠습니다ㅠㅠ 도와주세요ㅠㅠㅠㅠ
#include<stdio.h> #include<stdlib.h> #include<math.h> #define MAX_ELEMENT 100000 typedef struct{ long long int key; } element; typedef struct{ element heap[MAX_ELEMENT]; int heap_size; } HeapType; HeapType* create(){ return (HeapType*)malloc(sizeof(HeapType)); } void init(HeapType* h){ h->heap_size = 0; } void insert_min_heap(HeapType* h, element item){ // insert int i; i = ++(h->heap_size); while((i != 1) && (abs(item.key) < abs(h->heap[i/2].key))){ h->heap[i] = h->heap[i/2]; i /= 2; } h->heap[i] = item; } element delete_min_heap(HeapType* h){ // delete int parent, child; element item, temp; item = h->heap[1]; temp = h->heap[(h->heap_size)--]; parent = 1; child = 2; while(child <= h->heap_size){ if((child < h->heap_size) && (abs(h->heap[child].key) > abs(h->heap[child+1].key))){ child++; } if(abs(temp.key) <= abs(h->heap[child].key)){ break; } h->heap[parent] = h->heap[child]; parent = child; child *= 2; } h->heap[parent] = temp; return item; } int main(){ int n; HeapType* heap; heap = create(); init(heap); scanf("%d", &n); for(int i = 0; i<n; i++){ element x; scanf("%lld", &x); if(x.key != 0){ insert_min_heap(heap, x); } else if(x.key == 0){ if(heap->heap_size == 0){ printf("0\n"); } else{ element min_abs_value = delete_min_heap(heap); printf("%lld\n", min_abs_value); } } } free(heap); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
finn_02 3년 전
2%까지밖에 못가고 틀렸습니다 뜨는데 이유를 모르겠습니다ㅠㅠ 도와주세요ㅠㅠㅠㅠ