## 11150 - Cola

Moderator: Board moderators

ByOnti
New poster
Posts: 3
Joined: Thu Dec 16, 2010 1:39 pm

### Re: 11150 - Cola

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.

lupin
New poster
Posts: 1
Joined: Fri Mar 29, 2013 5:46 am

### Re: 11150 - Cola

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;

}
Last edited by brianfry713 on Mon Nov 24, 2014 11:58 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11150 - Cola

total is uninitialized and is used to terminate your loop.
Check input and AC output for thousands of problems on uDebug!

raihan_sust5
New poster
Posts: 6
Joined: Tue Jul 23, 2013 3:04 am

### Re: 11150 - Cola

i am having problem with input /output....nd i can't understand what they actually want me to do...anyone help me please

Omidoo
New poster
Posts: 1
Joined: Wed Jan 29, 2014 9:05 am

### Re: 11150 - Cola

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 ?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11150 - Cola

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
Check input and AC output for thousands of problems on uDebug!

mpmohi
New poster
Posts: 13
Joined: Wed Feb 26, 2014 10:15 pm

### Re: 11150 - Cola

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
Last edited by mpmohi on Sat Nov 22, 2014 10:45 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11150 - Cola

Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 11150 - Cola

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.

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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mpmohi
New poster
Posts: 13
Joined: Wed Feb 26, 2014 10:15 pm

### Re: 11150 - Cola

This Is ERFAN
New poster
Posts: 6
Joined: Thu Dec 04, 2014 11:40 pm

### Re: 11150 Cola

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;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: Suggest some easy problems to solve

Code: Select all

while(scanf("%d",&a) == 1)
{
int count = a, p, q = a, add;
http://acm.uva.es/board/viewtopic.php?f ... 9c#p373964
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

20717TZ
New poster
Posts: 33
Joined: Tue Apr 27, 2004 7:41 pm
Location: Santa Clara / Mountain View, CA, USA
Contact:

### Re: 11150 - Cola

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}
I Believe I Can - leestime.com

yasir.nabil
New poster
Posts: 2
Joined: Thu Jun 16, 2016 11:31 pm

### Re: 11150 - Cola

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;