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

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

在这里插入图片描述
测试样例

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.

题意: 给定整数 a a a b b b,同时给定 a a a的下限值 x x x b b b的下限值 y y y,你有 n n n次操作机会是 a − − a-- a或者 b − − b-- b。求出进行操作之后能够得到的 a ∗ b a*b ab的最小值。

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

我的AC代码

/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#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;
}

posted @   unique_pursuit  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示