Public Group

# ACM problem 10071

This topic is 3247 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to solve a ACM problem # 10071 This is the link of the problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=1012 I think i have fulfilled every conditions, but still it is showing wrong answer! I have tried a lot, but still could not figured out the problem. :( Indicating the problem will be enough.I will solve it by myself. Is there anyone who can help me out. Source: ------------------------------------------------------------------------- #include<stdio.h> int main() { int v,t; double a, s; while((scanf("%d %d",&v, &t)) == 2) { if (t==0 || t < 0) { s = 0; printf("%.0lf\n", s); continue; } a = (double)v/t; t *= 2; s = 0.5 * a * t * t; if(s<0) { s *= -1; printf("%.0lf\n", s); } else printf("%.0lf\n", s); } return 0; } ------------------------------------------------------------------

##### Share on other sites
I think you are being too sophisticated about signs. If the velocity is negative, you probably want to see negative displacement as well.

#include <stdio.h>int main() {  int v,t;  while (scanf("%d %d", &v, &t)==2)    printf("%d\n",2*v*t);  return 0;}

##### Share on other sites
and this is the solution with c++:

#include<iostream>
using namespace std;
int main()
{
int v,t;
while(cin>>v>>t)
cout<<2*v*t<<endl;
return 0;
}

and i have accepted when i send my answer

##### Share on other sites
Quote:
 Original post by iamcreasyI am trying to solve a ACM problem # 10071This is the link of the problem:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=1012I think i have fulfilled every conditions, but still it is showing wrong answer!I have tried a lot, but still could not figured out the problem. :(Indicating the problem will be enough.I will solve it by myself.Is there anyone who can help me out.Source:-------------------------------------------------------------------------#includeint main(){ int v,t; double a, s; while((scanf("%d %d",&v, &t)) == 2) { if (t==0 || t < 0) { s = 0; printf("%.0lf\n", s); continue; } a = (double)v/t; t *= 2; s = 0.5 * a * t * t; if(s<0) { s *= -1; printf("%.0lf\n", s); } else printf("%.0lf\n", s); } return 0;}------------------------------------------------------------------

the problem is you are assuming that there will be exactly two test case, in reality there will be many more case and you should read until EOF.

##### Share on other sites
Quote:
 Original post by Esoothe problem is you are assuming that there will be exactly two test case, in reality there will be many more case and you should read until EOF.

That's not right. He is reading for as long as he can read two arguments, which is precisely what he should do.

##### Share on other sites
Thanks,i solved it.

[Edited by - iamcreasy on December 3, 2009 1:08:36 PM]

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• ### Who's Online (See full list)

There are no registered users currently online

×