Skip to content

Instantly share code, notes, and snippets.

@atpons
Created July 6, 2017 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atpons/2218f1f389a38c0690763023e9477856 to your computer and use it in GitHub Desktop.
Save atpons/2218f1f389a38c0690763023e9477856 to your computer and use it in GitHub Desktop.
#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