1 solutions
-
0
C++ :
#include <iostream> using namespace std; int main(){ int max = 30 * 1200; int p = 30; int c = 1200; int s;//售价 int n; cin>>n; int price = p;//假设p元最划算 while(c > 0){ p++; c -= n;//每加1元,数量减少n张 s = p * c; // cout<<p<<" "<<c<<" "<<s<<endl; if(s > max){ max = s; price = p; } } cout<<price<<" "<<max<<endl; }
Python :
n = int(input()) x = 30 y = 1200 j = [] m = [] while(x <= y): z = x * y j.append(z) if(max(j) == x * y): m.append(x) x += 1 y -= n print(max(m), max(j))
- 1
Information
- ID
- 10664
- Time
- 1000ms
- Memory
- 16MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By