Created
July 6, 2017 11:39
-
-
Save atpons/2218f1f389a38c0690763023e9477856 to your computer and use it in GitHub Desktop.
This file contains 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> | |
int findCombi(int toHour) { | |
int aHour = 300; // 300 Hours | |
int aPrice = 100; // 100 JPY | |
int bHour = 500; // 500 Hours | |
int bPrice = 180; // 180 JPY | |
int aNum = toHour / aHour; | |
int bNum = toHour / bHour; | |
int a, b; | |
int allPrice = (toHour / aHour) * aPrice + (toHour / bHour) * bPrice; | |
int ableTime = (toHour / aHour) * aHour + (toHour / bHour) * bHour; | |
for (int i = aNum; i >= 0; i--) { | |
for (int j = bNum; j >= 0; j--) { | |
if (allPrice > i * aPrice + j * bPrice) { | |
if (i * aHour + j * bHour >= toHour) { | |
allPrice = i * aPrice + j * bPrice; | |
a = i; | |
b = j; | |
} | |
} | |
} | |
} | |
printf("最安値は電池Aが%d本、電池Bが%d本、価格は%d円です\n", a, b, allPrice); | |
return 0; | |
} | |
int main() { | |
int allNum; | |
printf("Input available time > "); | |
scanf("%d", &allNum); | |
findCombi(allNum); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment