Hello, world and everyone!
This is my first time to post in the forum in English, and my English is not so
good but i hope you can bear it and i'll try my best.
for iceAge:
Input :
- Code: Select all
5
0.17
0.00
0.00
0.00
0.00
0
Output :
- Code: Select all
13
;
Though this prob looks easy, but it really puzzled me much and I've already wasted two days solving this prob.
I've seen others' codes on this board but it seems hard for me to understand. Below is my own algorithm:
First calculate the average account ( ave = (int )total / n, note that the ave is the floor of the true ave ) . then divide the students into two parts:
the high students, whose account is bigger than ave and low student , whose account is lower or equal to ave.
it's said that the difference account can be 1 cent , so the legal account is ave and ave+1;
Then i found that we can exchange money between the two major part
and ignore the detail on single person. (obvious, low student needn't give out money). So the prob is simple now. Only two aspects:
low student get money from the high to increase their account to
at least ave;
high student get money from the low to reduce to ave+1 of ave;
The nest step is easy , since both of the require should be meeted, just print the bigger.
It is a fun thing. I originally write the material above because my prog always WA. But just after I post my code, and submit it again, I found it AC! I want to delete it all now but it really spend me some time to write the thing above so i remain it there.
Now I found out the main problem is that my origin prog cound't read the
input properly, i think int is enough to hold the account but that is the main thing cause my prog wrong.
- Code: Select all
int
readcount ( int n){
int i;
int total=0;
double count;
for ( i=0; i< n; i++){
scanf ("%lf\n", &count);
stdt[i] = count * 100;
total += count * 100;
}
return total;
}
I just change all the int into double including everyone's account and it is accepted.
I'm new in C and I puzzled about the way C read number and the calculation. Somtimes it read a 1.000 to 1.001(float) and sometimes 12/5=2.399999999999? Can anyone who has the experience tell me why and provide a way to handle the input. The single account is small and i think using double to handle it is a waste.
Hoping for your reply[/code]