알고리즘/문제
ALPS식 투표
미케코코
2019. 6. 30. 18:48
문제
처음에 이문제를 보았을 때 문제를 잘못이해 하고 코드를 작성하였다( 정말 최악인 안좋은 습관..)
이후 문제를 다시보니 어려운 문제가 아니였다. 포인트는 전대프연에 참가한 참가자들의 각각의 점수를
1~14까지 나누어서 이중 가장 큰 Index에 해당하는 인원의 Count 값을 올려주면 된다.
시간복잡도 부분을 생각하면 최악의 경우가 2500000*14이다 이로서 아래의 조건 1,2를 주의해서 코드를 작성하자!
(조건1. 전체득표율에 5%이상을 가져야지 후보에 오를 수 있다 아니면 탈락!)
(조건2. 출력하는 순서는 스태프 이름의 사전순이여야 한다.)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
import java.util.StringTokenizer;
public class Main{
public static double max=-1.0;
public static double [][] arr;
public static double []memoryNumber;
public static char [] memoryAlpha;
public static int [] result;
public static boolean flag=false;
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int number=sc.nextInt();
int totalNumber=sc.nextInt();
arr= new double[totalNumber][14];
memoryNumber=new double[totalNumber];
memoryAlpha=new char[totalNumber];
result=new int [totalNumber];
for(int i=0;i<totalNumber;i++)
{
char al=str.charAt(0);
double temp=sc.nextDouble();
if(number*0.05>temp)
{
continue;
}
memoryAlpha[i]=al;
memoryNumber[i]=temp;
}
for(int i=0;i<totalNumber;i++)
{
double temp=memoryNumber[i];
for(int j=0;j<14;j++)
{
arr[i][j]=(temp/(double)(j+1));
}
}
int count=0;
int indexi=0;
int indexj=0;
while(true)
{
if(count>=14)
{
break;
}
for(int i=0;i<totalNumber;i++)
{
for(int j=0;j<14;j++)
{
if(max<arr[i][j])
{
max=arr[i][j];
indexi=i;
indexj=j;
}
}
}
result[indexi]++;
arr[indexi][indexj]=-1.0;
indexi=0;
indexj=0;
count++;
max=-1.0;
}
for(int i=0;i<totalNumber;i++)
{
for(int j=0;j<totalNumber;j++)
{
if(memoryAlpha[i]<memoryAlpha[j])
{
char temp=memoryAlpha[i];
memoryAlpha[i]=memoryAlpha[j];
memoryAlpha[j]=temp;
int tempNumber=result[i];
result[i]=result[j];
result[j]=tempNumber;
}
}
}
for(int i=0;i<totalNumber;i++)
{
if(memoryAlpha[i]>='A' && memoryAlpha[i]<='Z')
{
System.out.println(memoryAlpha[i]+" "+result[i]);
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
https://www.acmicpc.net/problem/2817
2817번: ALPS식 투표
문제 전대프연(전국 대학생 프로그래밍 대회 동아리 연합)에서는 매년 프로그래밍 대회를 연다. 올해도 무사히 대회를 개최한 전대프연 회장 성진은 수고해준 스태프들에게 수고비를 주기로 하였다. 하지만 몇몇 스태프는 일을 열심히하지 않았기 때문에 성진은 일을 열심히 한 사람에게만 주기로했다. 하지만 일을 무진장 열심히 한 사람과 덜 열심히 한 사람에게 수고비를 똑같이 주는 것은 불공평하다. 고민을 한 성진은 수고비를 받을 사람을 선출하는 방식으로 ALPS(Al
www.acmicpc.net