Page 3 of 3

### Re: 11150 - Cola

Posted: Wed Dec 22, 2010 6:22 pm
Hi, I got AC with this function:

Code: Select all

``````int f (int n, int borrowed ) {
if (n==1) return 0;
if (n==2) return 0;
n = n/3 + f(n/3 + n%3, borrowed);
return n;
}``````
this function generate the additional bottles.

### Re: 11150 - Cola

Posted: Sun Mar 31, 2013 3:47 am
can tou help me... this is my submission.. i got TLE.

Code: Select all

``````#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<string.h>
//jangan lupa save as!!!
#define tahan system("PAUSE")

int cola(int n){
int bonus,sisa=n%3,total,pinjam;
if(total==1) return 0;
if(total==2) return 0;
if(sisa==2) pinjam=1;
else pinjam=0;
total=n+pinjam;
bonus=total/3;
sisa=total%3;
total=bonus+cola(bonus+sisa);
}

int main(){
int n;
while(scanf("%d", &n)){
if(n==0)break;
else printf("%d\n", cola(n));

}
return 0;

}``````

### Re: 11150 - Cola

Posted: Mon Apr 01, 2013 10:05 pm
total is uninitialized and is used to terminate your loop.

### Re: 11150 - Cola

Posted: Tue Jul 23, 2013 9:26 pm
i am having problem with input /output....nd i can't understand what they actually want me to do...anyone help me please

### Re: 11150 - Cola

Posted: Wed Jan 29, 2014 9:12 am
arsalan_mousavian wrote:can somebody tell me what is the correct output for my input ?

Code: Select all

``````1
2
3
4
5
6
7
8
9
10
15
20
30
40
50
100
150
190
199
200
``````

Code: Select all

``````2
3
5
6
8
9
11
12
14
15
23
30
45
60
75
150
225
285
299
300
``````
thanks
hey guys !

you sure output 11 is correct with input 7 ?

### Re: 11150 - Cola

Posted: Wed Jan 29, 2014 10:41 pm
7 full 0 empty - drink 7, trade in 6
2 full 1 empty - drink 2, trade in 3
1 full 0 empty - drink 1
output should be 10.

http://www.uvatoolkit.com/problemssolve.php

### Re: 11150 - Cola

Posted: Thu Sep 25, 2014 8:13 am
Hi guys check this..

Code: Select all

``````Accepted :)

``````
this code passes all the test case but gets wa..

for testCase http://www.udebug.com/UVa/11150

### Re: 11150 - Cola

Posted: Fri Sep 26, 2014 12:20 am
Try solving it without using floating point.

### Re: 11150 - Cola

Posted: Fri Sep 26, 2014 2:42 pm
If you solve with floating point you will have many problems like precision errors. So try to avoid it when possible. For this problem there is no need to use it.
Add epsilon to result

Code: Select all

``pf("%.lf\n", 4 + (n - 3) / 2) * 3 + 1e-8;``
I solved this problem with integers but with a loop. You did it in O(1).
Don't forget to remove your code after getting accepted.

### Re: 11150 - Cola

Posted: Sat Nov 22, 2014 10:49 pm

### Re: 11150 Cola

Posted: Sat Dec 06, 2014 10:33 pm
Getting time limit....help me plz

Code: Select all

``````#include<stdio.h>

int main()
{
int a;
while(1)
{
scanf("%d",&a);
while(q>=3)
{
p=q%3;
}
if(q==2) count++;
printf("%d\n",count);
}
return 0;
}
``````

### Re: Suggest some easy problems to solve

Posted: Sun Dec 07, 2014 8:56 am
When your code will terminate? You should read until EOF. Change you reading to

Code: Select all

``````while(scanf("%d",&a) == 1)
{
int count = a, p, q = a, add;``````
Hey ERFAN! There is already existing thread for this problem here
http://acm.uva.es/board/viewtopic.php?f ... 9c#p373964

### Re: 11150 - Cola

Posted: Mon Jan 26, 2015 5:34 am
If you guys think this problem from a different perspective, it's super easy:

Code: Select all

``````/* 11150 - Cola
Author: Peter Lee
Contact: leestime.com <at> gmail.com
Notes: 1. Let:
x = The price of an empty bottle
y = The price of the drink only in a bottle
Then:
x + y = 3*x => y = 2*x
2. Therefore, every two empty bottles can be used to trade
the drink only in a bottle.
*/

// Code removed

int T = N / 2 * 3;
if (N % 2)
++T;

// Code removed}
``````

### Re: 11150 - Cola

Posted: Thu Jun 23, 2016 7:37 pm
My code passes all the test cases but got WA......why?

Code: Select all

``````#include <stdio.h>

int func(int allBottle,int remain)
{
bottle = (allBottle+remain) / 3;
rem = (allBottle+remain) % 3;
add = bottle + rem - remain;
return bottle + func(add,2);
return bottle + func(add,1);
return bottle + func(add,0);
else
return bottle;
}

int main(void)
{
int n,x;
scanf("%d",&n);
x = n + func(n,0);
printf("%d\n",x);
return 0;
}
``````
Is there any cases that my code cannot passes??