11150 - Cola

All about problems in Volume 111. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Re: 11150 - Cola

Post by ByOnti » 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.

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

Re: 11150 - Cola

Post by lupin » 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);
    return total;
    }

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

}
please????
Last edited by brianfry713 on Mon Nov 24, 2014 11:58 pm, edited 1 time in total.
Reason: Added code blocks

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

Re: 11150 - Cola

Post by brianfry713 » Mon Apr 01, 2013 10:05 pm

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

Post by raihan_sust5 » 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

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

Re: 11150 - Cola

Post by Omidoo » 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 ?

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

Re: 11150 - Cola

Post by brianfry713 » 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
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

Post by mpmohi » 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
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

Post by brianfry713 » Fri Sep 26, 2014 12:20 am

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

Post by lighted » 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). :wink: :)
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

Post by mpmohi » Sat Nov 22, 2014 10:49 pm

Thanks brainfry713 and lighted for your helpful advise :)

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

Re: 11150 Cola

Post by This Is ERFAN » 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);
        int count=a,p,q=a,add;
        while(q>=3)
        {
            add=q/3;
            p=q%3;
            q=add+p;
            count=count+add;
        }
        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

Post by lighted » 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
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

Post by 20717TZ » 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
   Algorithm: ad-hoc
       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

Post by yasir.nabil » 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)
{
    int bottle,add,rem;
    bottle = (allBottle+remain) / 3;
    rem = (allBottle+remain) % 3;
    add = bottle + rem - remain;
    if((add+2)%3==0&&add!=0&&add>2)
        return bottle + func(add,2);
    else if((add + 1)%3==0&&add!=0)
        return bottle + func(add,1);
    else if(add%3==0&&add!=0)
        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??

Post Reply

Return to “Volume 111 (11100-11199)”