10137 - The Trip

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

Moderator: Board moderators

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

Re: 10137 - The Trip

Post by brianfry713 »

Try solving it without using floating point.

The correct output is "$0.01". I updated:
http://www.udebug.com/UVa/10137
Check input and AC output for thousands of problems on uDebug!

abccoder
New poster
Posts: 2
Joined: Mon Sep 15, 2014 1:30 pm

10137 - The Trip

Post by abccoder »

i got wrong answer.What's problem on my below code?

#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
int i;
long n;
double sum,c[1001],avg,pay,receive;
while(scanf("%ld",&n)>0)
{
sum=0.0;
pay,receive=0.0;
for(i=0;i<n;i++)
{
cin>>c;
sum+=c;
}
avg=(long)(sum/n);
for(i=0;i<n;i++)
{
if(avg>c)
{
pay+=avg-c;
}
else{
receive+=c-avg;
}


}
receive=-receive;
if(pay>receive)
cout<<"$"<<pay<<endl;
else
cout<<"$"<<receive<<endl;
}
return 0;
}

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

Re: 10137 - The Trip

Post by brianfry713 »

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

stevesJ03
New poster
Posts: 5
Joined: Tue Nov 11, 2014 6:50 pm

Re: 10137 - The Trip

Post by stevesJ03 »

Someone please help me!! what problems with my code ? why I got WA?

delete code after AC
Last edited by stevesJ03 on Wed Nov 12, 2014 4:53 pm, edited 1 time in total.

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

Re: 10137 - The Trip

Post by brianfry713 »

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

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

Re: 10137 - The Trip

Post by lighted »

A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

stevesJ03
New poster
Posts: 5
Joined: Tue Nov 11, 2014 6:50 pm

Re: 10137 - The Trip

Post by stevesJ03 »

thanks, I get AC :D

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10137 - The Trip

Post by Shahidul.CSE »

Why I am getting WA with my bellow code?

Code: Select all

Accepted
Last edited by Shahidul.CSE on Thu Dec 11, 2014 5:58 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

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

Re: 10137 - The Trip

Post by lighted »

Try to check input in this thread before posting.
brianfry713 wrote:Input:

Code: Select all

21 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.01 
0.03 
0
AC output:

Code: Select all

$0.01
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mac07
New poster
Posts: 1
Joined: Wed Aug 12, 2015 3:37 pm

Re: 10137 - The Trip

Post by mac07 »

Code: Select all

//C++ Source
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
using namespace std;
 
 
int main()
{
 
 int students, counter=0;
 double payments[1000], total=0, deficits[1000], surplus[1000];
 
 while(1)
 {
 cin >> students;
 total = 0;
 if (students == 0)
 {
 for (int i=0; i<counter; i++)
 {
 if (deficits[i] < surplus[i]) deficits[i] = surplus[i];  //line 14
 
 cout << '$' << setprecision(2) << fixed << deficits[i] << endl;
 }
 
 return 0;
 }
 
 for (int i=0; i<students; i++) {cin >> payments[i]; total+= payments[i];}
 
 total /= students;
 
 deficits[counter] = 0;
 surplus[counter] = 0;
 for (int i=0; i<students; i++)
 if (payments[i] < total) deficits[counter] += (floor((total - payments[i])*100))/100;//line 28
 else if (payments[i] > total) surplus[counter] += (floor((-total + payments[i])*100))/100; //line 29
 
 counter++;
 }
 
 return 0;
}

In line 14, why do we want that if statement? And in line 28 & 29, why do we round off the difference ?
Also, I didnt understand this part "After the trip,each student's expenses are tallied and money is exchanged so that net cost to the each is same,to within one cent".
to within one cent?
Can someone please explain these?
Please help
Last edited by brianfry713 on Wed Aug 19, 2015 8:51 pm, edited 1 time in total.
Reason: Added code block

Post Reply

Return to “Volume 101 (10100-10199)”