10137 - The Trip
Moderator: Board moderators
-
- New poster
- Posts: 28
- Joined: Mon Nov 15, 2004 5:00 pm
Actually I find my fault with the programming-challenges judge than with this judge. I had failed attempts with LC-Display(110104/706) and WERTYU(110301/10082) in which both got P.E. and W.A. respectively in programming-challenges but were instantly acceted by this judge. What's your code for The Trip like?
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
Yes, I have experienced similar situation, too. I had P.E. on LC-Display in this judge. But after getting P.E. on Programming-challenges, I changed the code & got AC in UVa, but Programming-challenges judge is still unmoved with its P.E. I have certain troubles with a few other problems, too. But the problem The Trip was surprisingly accepted in PC with a code which even I don't think to be my most correct version for this problem.SePulTribe wrote:Actually I find my fault with the programming-challenges judge than with this judge. I had failed attempts with LC-Display(110104/706) and WERTYU(110301/10082) in which both got P.E. and W.A. respectively in programming-challenges but were instantly acceted by this judge.
Here is my code - [cpp]
/*@begin_of_source_code*/
/* The Trip */
/* AC in PC but WA in UV*/
#include<stdio.h>
#define size 1003
int main(void)
{
long n,i;
double avg,sum,sumup,sumdown,out,data[size];
while(scanf("%ld",&n)==1)
{
if(!n)
break;
sum = 0.0;
for(i=0;i<n;i++)
{
scanf("%lf",&data);
sum += data;
}
avg = sum/n;
avg = (long)(avg * 100 + 0.5);
avg /= 100;
sumup = sumdown = 0.0;
for(i=0;i<n;i++)
{
if(data < avg)
sumdown += (avg - data);
else
sumup += (data - avg);
}
if(sumup<sumdown)
out = sumup;
else
out = sumdown;
printf("$%.2lf\n",out);
}//end case while
return 0;
}
/*@end_of_source_code*/
[/cpp]
You should never take more than you give in the circle of life.
-
- New poster
- Posts: 28
- Joined: Mon Nov 15, 2004 5:00 pm
-
- New poster
- Posts: 28
- Joined: Mon Nov 15, 2004 5:00 pm
-
- New poster
- Posts: 28
- Joined: Mon Nov 15, 2004 5:00 pm
After reading the post by waseem50 I finally got it accepted by UVA! Try it:Mohammad Mahmudur Rahman wrote:I don't really know what's the problem with this problem. I have long been in troubles with this one & tried in various ways all of which resulted in WA. But just now I've submitted the same problem in the programming-Challenge judge where it recieved AC. Can someone tell me what's wrong with this problem in UVa judge?
[c]#include <math.h>
#include <stdio.h>
long double round(long double x, int precision)
{
return floor(x*pow(10.0,(long double)precision)+0.5)/pow(10.0,(long double)precision);
}
int main(void)
{
int no, ii;
long double total, above, below, right, student[1000];
while (1)
{
scanf("%d\n", &no);
if (!no)
break;
for (ii = 0, total = 0; ii < no; ii++)
{
scanf("%Lf\n", &student[ii]);
total += student[ii];
}
right = round((total / no), 2);
above = below = 0;
for (ii = 0; ii < no; ii++)
{
if (student[ii] < right)
below += right - student[ii];
if (student[ii] > right)
above += student[ii] - right;
}
if (above == 0)
above = below;
if (below == 0)
below = above;
printf("$%.2Lf\n", round(((below < above) ? below : above), 2));
}
return 0;
}
[/c]
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
-
- New poster
- Posts: 28
- Joined: Mon Nov 15, 2004 5:00 pm
I found something ...
I once take the inputs in this way:
scanf("%d",&n); /* n */
scanf("%Lf",&x); /* money */ ....
==> WA
now:
scanf("%d\n",&n);
scanf("%Lf\n",&x); .....
==> Accepted...
Everything else are exactly the same, only the CR characters in the format strings were added.
Does anybody have any ideas about why?
scanf("%d",&n); /* n */
scanf("%Lf",&x); /* money */ ....
==> WA
now:
scanf("%d\n",&n);
scanf("%Lf\n",&x); .....
==> Accepted...
Everything else are exactly the same, only the CR characters in the format strings were added.
Does anybody have any ideas about why?
10137
I read all the posts about the problem. I considered the extra pennies , extreme cases etc. I am affraid that I miss something essential about c++ programming and portability. Thanks in advance for any help.
Code: Select all
/* @JUDGE_ID: xx 10137 C++ "The Trip" */
#include <iostream>
#include <iomanip>
using namespace std ;
int main(){
short sub ;
long people=1 , coun , residue , average , nmore , nless ;
long money[1001] , sum , more , less ;
long double hold , result ;
while (people!=0){
sum = 0 ;
cin >> people ;
if (people==0) break ;
for(coun=1 ; coun<=people ; ++coun){
cin >> hold ;
money[coun] = (int)(hold*100) ;
sum += money[coun] ;}
residue =sum%people ;
average = (int)((sum-residue)/people) ;
if (residue==0) sub = 0 ;
else sub = 1 ;
more = 0 ;
nmore = 0 ;
less = 0 ;
nless = 0 ;
for(coun=1 ; coun<=people ; ++coun)
if (money[coun]>average){
more += money[coun] - average - sub ;
++nmore ;}
else {
less += average - money[coun] ;
++nless ;}
cout.setf(ios::fixed) ;
cout.precision(2) ;
if (residue > nmore)
result = static_cast<double>(more)/100 ;
else
result = static_cast<double>(less)/100 ;
cout << '$' << result << endl ;
}
return 0;}
10137: The Trip
Hey... I guess I'm having problem passing one of the test cases of this problem... Please give me a hint as to what I'm missing in this task. My solution is fairly simple: I'm finding the arithmetic mean, and then the differences...
Here is my code:
VAR N: integer;
A: ARRAY[1..1000] of double;
Answer: double;
procedure ReadInfo;
VAR I: integer;
begin
FOR I:=1 TO N DO ReadLn(A);
end;
procedure WriteOutput;
begin
WriteLn('$', Answer:4:2);
end;
procedure Solve;
VAR I: integer;
AMean: double;
A1, A2: double;
begin
AMean:=0; A1:=0; A2:=0;
FOR I:=1 TO N DO
AMean:=AMean+A;
AMean:=Round((AMean / N)*100)/100;
FOR I:=1 TO N DO
IF A > AMean
then A1:=A1 + A-AMean
else A2:=A2 + Amean-A;
IF A1<A2 then
Answer:=A1 else Answer:=A2;
end;
begin
ReadLn(N);
WHILE (N<>0) DO
begin
ReadInfo;
Solve;
WriteOutput;
ReadLn(N);
end;
end.
Here is my code:
VAR N: integer;
A: ARRAY[1..1000] of double;
Answer: double;
procedure ReadInfo;
VAR I: integer;
begin
FOR I:=1 TO N DO ReadLn(A);
end;
procedure WriteOutput;
begin
WriteLn('$', Answer:4:2);
end;
procedure Solve;
VAR I: integer;
AMean: double;
A1, A2: double;
begin
AMean:=0; A1:=0; A2:=0;
FOR I:=1 TO N DO
AMean:=AMean+A;
AMean:=Round((AMean / N)*100)/100;
FOR I:=1 TO N DO
IF A > AMean
then A1:=A1 + A-AMean
else A2:=A2 + Amean-A;
IF A1<A2 then
Answer:=A1 else Answer:=A2;
end;
begin
ReadLn(N);
WHILE (N<>0) DO
begin
ReadInfo;
Solve;
WriteOutput;
ReadLn(N);
end;
end.
Thanks. I just made a mistake with the calculation of average. With your help, I got AC.
Mohammad Mahmudur Rahman wrote:Yes, I have experienced similar situation, too. I had P.E. on LC-Display in this judge. But after getting P.E. on Programming-challenges, I changed the code & got AC in UVa, but Programming-challenges judge is still unmoved with its P.E. I have certain troubles with a few other problems, too. But the problem The Trip was surprisingly accepted in PC with a code which even I don't think to be my most correct version for this problem.SePulTribe wrote:Actually I find my fault with the programming-challenges judge than with this judge. I had failed attempts with LC-Display(110104/706) and WERTYU(110301/10082) in which both got P.E. and W.A. respectively in programming-challenges but were instantly acceted by this judge.
Here is my code - [cpp]
/*@begin_of_source_code*/
/* The Trip */
/* AC in PC but WA in UV*/
#include<stdio.h>
#define size 1003
int main(void)
{
long n,i;
double avg,sum,sumup,sumdown,out,data[size];
while(scanf("%ld",&n)==1)
{
if(!n)
break;
sum = 0.0;
for(i=0;i<n;i++)
{
scanf("%lf",&data);
sum += data;
}
avg = sum/n;
avg = (long)(avg * 100 + 0.5);
avg /= 100;
sumup = sumdown = 0.0;
for(i=0;i<n;i++)
{
if(data < avg)
sumdown += (avg - data);
else
sumup += (data - avg);
}
if(sumup<sumdown)
out = sumup;
else
out = sumdown;
printf("$%.2lf\n",out);
}//end case while
return 0;
}
/*@end_of_source_code*/
[/cpp]
10137 Assistance
Can anyone please provide some assistance as to why I am getting WA on this problem? Thank you.
Code: Select all
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stdlib.h>
#include <math.h>
using namespace std;
vector<int> students;
int main(int argc, char *argv[])
{
int n,i,pool = 0;
while (cin >> n)
{
if (n == 0)
{
break;
}
int tot = 0;
double val;
for (i = 0; i < n; i++)
{
cin >> val;
val *= 100;
students.push_back((int)val);
tot += (int)val;
}
double db = (double)(tot)/(double)n;
int avg = (tot/n);
int cl = (int)ceil(db);
int rem = tot % n;
for (int i = 1; i <= rem; i++)
{
vector<int>::iterator maxiter = max_element(students.begin(), students.end());
pool += abs(*maxiter - cl);
students.erase(maxiter);
}
for (vector<int>::iterator iter = students.begin(); iter != students.end(); iter++)
{
pool += abs(*iter - avg);
}
pool /= 2;
cout << "$" << setiosflags(ios::fixed) << setprecision(2)<< (pool/100.00) << endl;
pool = 0;
students.clear();
}
}
The Trip 10137
You need to find the MINUMUM amount required to be exchanged. For that matter you have to find a way to test ONLY UPTO TWO DECIMAL PLACES as to what is the corrent amount. Secondly your A. Mean should also be rounded upto two decimal places.
Example : in the second test case given in the problem, one person has spent 3.01, so all he needs to add to his spent amount is 5.99, not 6. That makes the net amount 6+5.99 - 11.99.
Hope you got the idea.
Example : in the second test case given in the problem, one person has spent 3.01, so all he needs to add to his spent amount is 5.99, not 6. That makes the net amount 6+5.99 - 11.99.
Hope you got the idea.
There are 10 types of people. Those who can read binary and those who cant
http://acm.uva.es/problemset/usersjudge.php?user=37504
http://acm.uva.es/problemset/usersjudge.php?user=37504