|
|
back to boardDiscussion of Problem 1607. TaxiHelp, please. WA#21 Posted by Nikolay 25 Oct 2008 16:55 #include <stdio.h> int calculate(int a,int b,int c,int d); void main(){ int a=0,b=0,c=0,d=0; scanf("%d%d%d%d", &a, &b, &c, &d); printf("%d\n",calculate(a,b,c,d)); } int calculate(int a,int b,int c,int d){ bool m=true; if (a>c) return a; if (a==c||a+b>c) return c; if (c-d<a) return a+b;
while(1){ if (m){//c-a>=b){ a+=b;m=false; if (a+b>c-d) return a; } else if (!m){//&&c-a>=d){ c-=d;m=true; if (c<a+b) return c; } //else return a; } } |
|
|