Skip to content

Commit 59bdd1b

Browse files
committed
solve 1942
1 parent 58ae6c4 commit 59bdd1b

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

Diff for: 1942/unoccupied.sln

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unocupide", "Unocupide\Unocupide.csproj", "{6BCE1CDF-2DB5-4490-BF39-178A401E8B18}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(SolutionProperties) = preSolution
14+
HideSolutionNode = FALSE
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{6BCE1CDF-2DB5-4490-BF39-178A401E8B18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{6BCE1CDF-2DB5-4490-BF39-178A401E8B18}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{6BCE1CDF-2DB5-4490-BF39-178A401E8B18}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{6BCE1CDF-2DB5-4490-BF39-178A401E8B18}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal

Diff for: 1942/unoccupied/Program.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Solution solution = new Solution();
2+
3+
int ans = solution.SmallestChair([[4,5],[12,13],[5,6],[1,2],[8,9],[9,10],[6,7],[3,4],[7,8],[13,14],[15,16],[14,15],[10,11],[11,12],[2,3],[16,17]],15);
4+
5+
Console.WriteLine(ans);

Diff for: 1942/unoccupied/solution.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Reflection.Metadata.Ecma335;
2+
3+
public class Solution {
4+
public int SmallestChair(int[][] times, int targetFriend) {
5+
int targetArival = times[targetFriend][0];
6+
int[] arivals = times.Select(x => x[0]).ToArray();
7+
Array.Sort(arivals,times);
8+
9+
PriorityQueue<int[],int> leavingTimes= new PriorityQueue<int[],int>();
10+
PriorityQueue<int,int> availableSeat = new PriorityQueue<int,int>();
11+
for (int i = 0;i<times.Length;i++){
12+
availableSeat.Enqueue(i,i);
13+
}
14+
15+
foreach (int[] time in times){
16+
17+
while (leavingTimes.Count>0 && time[0]>=leavingTimes.Peek()[0])
18+
{
19+
int [] availableChair = leavingTimes.Dequeue();
20+
availableSeat.Enqueue(availableChair[1],availableChair[1]);
21+
}
22+
if (time[0]==targetArival){
23+
return availableSeat.Dequeue();
24+
}
25+
int chair = availableSeat.Dequeue();
26+
leavingTimes.Enqueue([time[1],chair],time[1]);
27+
}
28+
return 0;
29+
}
30+
31+
32+
}

Diff for: 1942/unoccupied/unoccupied.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

0 commit comments

Comments
 (0)