Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 구현
- Stack 이란
- dfs
- 5397
- 시간 복잡도
- 별 찍기 10
- 1764
- 백준 5397
- 스택의 특징
- 백준 1158
- 버킷 정렬
- 조세퍼스 순열
- 풀이
- c#
- 백준 17779
- ㅣ풀이
- 해시구현
- qorwns
- 백준 2447
- AVL 시간 복잡도
- heap
- 백준 17822
- C/C++ 구현
- 백준 17471
- 백준
- 백준 1406
- 자료구조
- 해시 구현
- 게리멘더링2
- 원판 돌리기
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 11652] 카드 본문
https://www.acmicpc.net/problem/11652
11652번: 카드
준규는 숫자 카드 N장을 가지고 있다. 숫자 카드에는 정수가 하나 적혀있는데, 적혀있는 수는 -262보다 크거나 같고, 262보다 작거나 같다. 준규가 가지고 있는 카드가 주어졌을 때, 가장 많이 가지고 있는 정수를 구하는 프로그램을 작성하시오. 만약, 가장 많이 가지고 있는 정수가 여러 가지라면, 작은 것을 출력한다.
www.acmicpc.net
요구사항
주어진 입력 중 가장 많이 입력된 수 출력하기
풀이
카드의 숫자는 1000000개이다
입력 받은 후 정렬한다.
n개를 탐색하며 가장 많이 나오는 숫자를 찾는다.
#include <stdio.h>
#include <algorithm>
#include <list>
#include <iostream>
using namespace std;
struct NODE {
int prev;
int next;
int val;
};
const int MAX = 1000000+1;
long long map[MAX];
long long buf[MAX];
void mer(long long arr[],int len)
{
if(len<2){
return;
}
int i,j,mid,k;
i=0;
mid=len/2;
j=mid;
k=0;
mer(arr,mid);
mer(arr+mid,len-mid);
while(i<mid && j<len){
if(arr[i]<arr[j]){
buf[k++]=arr[i++];
}
else{
buf[k++]=arr[j++];
}
}
while(i<mid){
buf[k++]=arr[i++];
}
while(j<len){
buf[k++]=arr[j++];
}
for(int i=0 ; i <len ; i++){
arr[i]=buf[i];
}
}
int n;
int main(){
scanf("%d",&n);
for(int i=0 ; i < n ; i++){
long long x;
scanf("%lld",&x);
map[i]=x;
}
mer(map,n);
long long ans=map[0];
long long maxv=0;
long long cnt=1;
for(int i=0 ; i < n-1 ; i++){
if(map[i]==map[i+1]){
cnt++;
}
else{
cnt=1;
}
if(cnt>maxv)
{
maxv=cnt;
ans=map[i];
}
}
cout<<ans<<endl;
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 4195] 친구 네트워크 (0) | 2020.01.14 |
---|---|
[백준 5052] 전화번호 목록(20200514 수정) (0) | 2020.01.14 |
[백준 3047]ABC (0) | 2020.01.14 |
[백준 11657] 타임 머신 (0) | 2020.01.14 |
[백준 1504] 특정한 최단 경로 (0) | 2020.01.14 |
Comments