Last active
August 29, 2015 13:59
-
-
Save Denommus/10566040 to your computer and use it in GitHub Desktop.
Cookie problem from GSoC 2014 in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| double calculateTime(double c, double f, double x) { | |
| double totalTime = 0; | |
| int n = 0; | |
| double timeWithCurrent, timeForFarm, timeWithFarm; | |
| do { | |
| timeWithCurrent = x/((f*n)+2); | |
| timeForFarm = c/((f*n)+2); | |
| timeWithFarm = timeForFarm+(x/(((1+n)*f)+2)); | |
| if(timeWithFarm > timeWithCurrent) { | |
| totalTime += timeWithCurrent; | |
| break; | |
| } else { | |
| n += 1; | |
| totalTime += timeForFarm; | |
| } | |
| } while (1); | |
| return totalTime; | |
| } | |
| int main() { | |
| printf("%.7f\n", calculateTime(30.0, 2.0, 100.0)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment