Problem Description
Problem Analysis
The idea of a Priority Queue is used.
So we can “push” all the floors that everyone needs to reach into the queue.
Then we can just extract them directly when needed.
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
| #include<stdio.h>
#include<queue>
using namespace std;
struct node {
int x;
bool friend operator<(node A,node B) {
return A.x>B.x;
}
} a;
int main() {
int T;
scanf("%d",&T);
while(T--) {
int n;
scanf("%d",&n);
priority_queue<node>q;
for(int i=0; i<n; i++) {
scanf("%d",&a.x);
q.push(a);
}
int sum=0,last=0;
while(!q.empty()) {
a=q.top();
if(a.x==last)
sum+=1;
else
sum+=(a.x-last+1)*6;
last=a.x;
q.pop();
}
printf("%d\n",sum+last*4);
}
return 0;
}
|
Problem link: HDU [4505] Little Q Series Story — Love in the Elevator