10901 - Ferry Loading III
Moderator: Board moderators
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
At the begining the ferry is on the left bank waiting for a car. In 10 minutes a car arrives to the right bank while there is no car on the left bank at that time. Therefore, the ferry heads for the right bank. It arrives there at 20, loads the car and returns back to the left bank. After returning (at 30) it unloads the first car and loads the second one, as it has already come (at 25). Further it travels to the right bank, unloads the second car (at 40) and returns back on the left bank (at 50), again, where it loads the last car and deliver it to the right bank at 60.predator wrote:i am having a difficulty in understanding the statement of the problem. can any one please explain me the 2nd sample
Why Wrong Answer?
Please help.
Code: Select all
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <stack>
#include <queue>
typedef unsigned long long ll;
using namespace std;
queue<int> l;
queue<int> r;
int main()
{
int c; scanf("%d", &c);
while (c--){
int n,t,m;
scanf("%d %d %d", &n, &t, &m);
bitset<10000> posicoes;
vector<int> listaL, listaR;
posicoes.reset();
int indice = 0;
for (int i = 0; i<m; i++){
int time; char side[10];
scanf("%d %s", &time, side);
if (side[0]=='l'){
l.push(time);
} else {
r.push(time);
posicoes[indice++] = true;
}
}
int atual = 0;
int carga;
bool side = false;
// false = left
// true = right
while (!l.empty() || !r.empty()){
if (!l.empty() && !r.empty()) {
if(l.front() > atual && r.front() > atual) {
if(l.front() > r.front()) {
atual += r.front() - atual;
if(!side) atual += t;
side = true;
}
else {
atual += l.front() - atual;
if(side) atual += t;
side = false;
}
}
} else {
if (l.empty()) {
if (r.front() > atual) {
atual += r.front() - atual;
if(!side) atual += t;
side = true;
}
}
else {
if (l.front() > atual) {
atual += l.front() - atual;
if(side) atual += t;
side = false;
}
}
}
if (!side) {
carga = 0;
while (carga < n && !l.empty() && l.front() <= atual) {
listaL.push_back(atual+t);
l.pop();
carga++;
}
atual += t;
side = true;
}
else {
carga = 0;
while (carga < n && !r.empty() && r.front() <= atual) {
listaR.push_back(atual+t);
r.pop();
carga++;
}
atual += t;
side = false;
}
}
int indr=0, indl=0;
for (int i = 0; i<m; i++){
if (posicoes[i]){
printf("%d", listaR[indr++]);
} else printf("%d", listaL[indl++]);
printf("\n");
}
if (c>0) printf("\n");
listaL.clear();
listaR.clear();
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10901 - Ferry Loading III
Input:Correct output:
Code: Select all
1
3 5 7
0 left
1 left
2 left
3 left
5 left
5 right
11 right
Code: Select all
5
15
15
15
25
10
20
Check input and AC output for thousands of problems on uDebug!
-
- Learning poster
- Posts: 99
- Joined: Fri Aug 17, 2012 9:23 pm
- Location: Dhaka
- Contact:
Re: 10901 - Ferry Loading III
@brianfry713... is it legal that arrival times are same ??? In arrival time 5 ,if a cargo comes in left bank,how at the same times another cargo can come in right bank ??? the problem statement says... " The arrival times for each test case are strictly increasing...."brianfry713 wrote:Input:Correct output:Code: Select all
1 3 5 7 0 left 1 left 2 left 3 left 5 left 5 right 11 right
Code: Select all
5 15 15 15 25 10 20
![:(](./images/smilies/icon_frown.gif)
I am really confused ... please help !!!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10901 - Ferry Loading III
Read this entire thread. Your question has already been answered by the problem setter.
Check input and AC output for thousands of problems on uDebug!
-
- Learning poster
- Posts: 99
- Joined: Fri Aug 17, 2012 9:23 pm
- Location: Dhaka
- Contact:
Re: 10901 - Ferry Loading III
Thanks a lot brianfry713.... for your quick reply...brianfry713 wrote:Read this entire thread. Your question has already been answered by the problem setter.
![:)](./images/smilies/icon_smile.gif)
It's my fault....
![:x](./images/smilies/icon_mad.gif)
-
- Learning poster
- Posts: 99
- Joined: Fri Aug 17, 2012 9:23 pm
- Location: Dhaka
- Contact:
Re: 10901 - Ferry Loading III
Last edited by Mukit Chowdhury on Thu Dec 20, 2012 8:11 am, edited 2 times in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10901 - Ferry Loading III
For input:My AC code prints:
Instead of using a map, I just keep track of the finish times of the left and right queues, and the order of which side each input was.
Code: Select all
1
1 5 2
0 left
0 left
Code: Select all
5
15
Check input and AC output for thousands of problems on uDebug!
-
- Learning poster
- Posts: 99
- Joined: Fri Aug 17, 2012 9:23 pm
- Location: Dhaka
- Contact:
Re: 10901 - Ferry Loading III
I haven't understood what have you done... but I have used 4 queue this time... two are for value keeping and two are for index keeping of that values... would you give me some critical input for my code,please ???brianfry713 wrote:For input:My AC code prints:Code: Select all
1 1 5 2 0 left 0 left
Instead of using a map, I just keep track of the finish times of the left and right queues, and the order of which side each input was.Code: Select all
5 15
Code: Select all
Accepted .........
Last edited by Mukit Chowdhury on Thu Dec 20, 2012 8:13 am, edited 3 times in total.
-
- Learning poster
- Posts: 99
- Joined: Fri Aug 17, 2012 9:23 pm
- Location: Dhaka
- Contact:
Re: 10901 - Ferry Loading III
for input...
my codes shows...
These are correct,right ???
Code: Select all
7
1 5 2
0 right
0 left
2 5 2
0 left
0 left
2 5 2
0 right
0 right
3 5 7
0 left
1 left
2 left
3 left
5 left
5 right
11 right
1 5 2
0 right
1 left
2 5 2
0 right
6 right
2 5 2
0 right
5 right
Code: Select all
10
5
5
5
10
10
5
15
15
15
25
10
20
10
15
10
20
10
10
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10901 - Ferry Loading III
You can generate I/O at http://www.uvatoolkit.com/problemssolve.php
Check input and AC output for thousands of problems on uDebug!
-
- Learning poster
- Posts: 99
- Joined: Fri Aug 17, 2012 9:23 pm
- Location: Dhaka
- Contact:
Re: 10901 - Ferry Loading III
I tried there but haven't found any error ... ![:(](./images/smilies/icon_frown.gif)
So I thought if you can find any bug seeing my code by your experience & can give me some critical input...![:(](./images/smilies/icon_frown.gif)
Would you,please?
![:(](./images/smilies/icon_frown.gif)
So I thought if you can find any bug seeing my code by your experience & can give me some critical input...
![:(](./images/smilies/icon_frown.gif)
Would you,please?