0
点赞
收藏
分享

微信扫一扫

B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)

原题链接: ​​http://codeforces.com/contest/1409/problems​​

B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_ios
测试样例

input
7
10 10 8 5 3
12 8 8 7 2
12343 43 4543 39 123212
1000000000 1000000000 1 1 1
1000000000 1000000000 1 1 1000000000
10 11 2 1 5
10 11 9 1 10
output
70
77
177177
999999999000000000
999999999
55
10

Note

In the first test case of the example, you need to decrease b three times and obtain 10⋅7=70.

In the second test case of the example, you need to decrease a one time, b one time and obtain 11⋅7=77.

In the sixth test case of the example, you need to decrease a five times and obtain 5⋅11=55.

In the seventh test case of the example, you need to decrease b ten times and obtain 10⋅1=10.

题意: 给定整数B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_#define_02B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_数学_03,同时给定B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_#define_02的下限值B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_数学_05B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_数学_03的下限值B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_数学_07,你有B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_数学_08次操作机会是B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_#define_09或者B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_ios_10。求出进行操作之后能够得到的B. Minimum Product(数学问题)Codeforces Round #667 (Div. 3)_数学_11的最小值。

解题思路: 这是需要一个常识的,就是如果我们想要让两个数相乘最小,那么我们必然会让那个小的更小。 但这题又有点特殊,因为它规定了下限,同时我们也有限定的操作次数,我们无法确定对哪个操作,但根据第一句话我们一定知道,我们要让这两个数其中一个更小,越小越好。 既然是这样,虽然我们不知道要对哪个进行操作,但我们知道如果我们确定了一个操作数,那么我们一定会让它尽可能最小,直到达到下限或者操作次数用完,否则不会对另一个操作数进行处理。OK,那就好办了,由于操作数只有两个,我们计算一下取最小值即可。

我的AC代码

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
int t;
ll a,b,x,y,n;
while(cin>>t){
while(t--){
cin>>a>>b>>x>>y>>n;
//乘积要最小就要让一方大的最小。
ll temp,ans=0,temp1=n,a1=a,b1=b;
temp=min(b-y,temp1);
b-=temp;
temp1-=temp;
if(temp1>0){
temp=min(a-x,temp1);
a-=temp;
temp1-=temp;
}
ans=a*b;
temp=min(a1-x,n);
a1-=temp;
n-=temp;
if(n>0){
temp=min(b1-y,n);
b1-=temp;
n-=temp;
}
ans=min(a1*b1,ans);
cout<<ans<<endl;
}
}
return 0;
}


举报

相关推荐

0 条评论