Moderator: Board moderators
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.
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?
/* @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;}Mohammad Mahmudur Rahman wrote: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.
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.
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[i]);
sum += data[i];
}
avg = sum/n;
avg = (long)(avg * 100 + 0.5);
avg /= 100;
sumup = sumdown = 0.0;
for(i=0;i<n;i++)
{
if(data[i] < avg)
sumdown += (avg - data[i]);
else
sumup += (data[i] - avg);
}
if(sumup<sumdown)
out = sumup;
else
out = sumdown;
printf("$%.2lf\n",out);
}//end case while
return 0;
}
/*@end_of_source_code*/
[/cpp]
#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();
}
}
Users browsing this forum: No registered users and 1 guest