洛谷:P1909
OJ: P4950
方法一:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <iostream> #include <algorithm> using namespace std; int main(){ int n,a[3],b[3],c[3],s=0; cin>>n; for (int i = 0; i <3 ; i++)cin>>a[i]>>b[i]; for (int i = 0; i <3; i++){ for (int j =1; j <=10000; j++) { if(a[i]*j>=n){ c[i]=b[i]*j; break; } } } s=c[0]; for (int i = 0; i <3; i++){ s=min(s,c[i]); } cout<<s; } |
方法二:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <iostream> #include <algorithm> using namespace std; int main(){ float n; int m; int minn=0x7fffffff; int a[3][2]; cin>>n; for (int i = 0; i <3; i++)cin>>a[i][0]>>a[i][1]; for (int i = 0; i < 3; i++) { m=ceil(n/a[i][0])*a[i][1]; minn=min(minn,m); } cout<<minn; } |