-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10261_ferryloading.cpp
More file actions
77 lines (74 loc) · 1.13 KB
/
Copy path10261_ferryloading.cpp
File metadata and controls
77 lines (74 loc) · 1.13 KB
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
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
using namespace std;
int Flen;
#define size 101
int Carlen[size];
int Len;
void readcase(){
int temp;
cin >> Flen;
Len = 0;
while (cin >> temp){
if (temp == 0)break;
Carlen[Len++] = temp;
}
}
char p[100];
double Left, Right;
int Ans;
void solvecase()
{
Left = Right = 0;
Ans = 0;
for (int i = 0; i < Len; i++)
{
if (Left <= Right)
{
if (Left + Carlen[i]/100 <= Flen)
{
p[i] = 'l';
Left += Carlen[i] / 100;
Ans++;
}
}
else
{
if (Right + Carlen[i]/100 <= Flen)
{
p[i] = 'r';
Right += Carlen[i] / 100;
Ans++;
}
}
}
}
int f = 1;
void printcase()
{
if (f == 0)
printf("\n");
f = 0;
printf("%d\n", Ans);
for (int i = 0; i < Ans; i++)
{
if (p[i] == 'l')
printf("port\n");
else if (p[i] == 'r')
printf("starboard\n");
}
}
int main(){
int t;
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//int Flen;
cin >> t;
for (int T = 1; T <= t; T++)
{
readcase();
solvecase();
printcase();
}
}