Educational Codeforces Round 86 (Rated for Div. 2) 比赛人数15356
[codeforces 1342A] Road To Zero 两种选择有优劣
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址https://codeforces.com/contest/1342/problem/A
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
A - Road To Zero | GNU C++17 | Accepted | 31 ms | 0 KB |
第一发WA后,才认真的考虑了两种方式的差异。
发现两次a的效果等价于一次b的效果
若2*a<b,可以考虑统统用a来操作
若2*a>=b,才考虑b也参与进来。
题目一旦有坑点,难度马上就上来了。
AC代码如下
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
LL sum;
int main(){
int t,x,y,a,b;
scanf("%d",&t);
while(t--){
sum=0;
scanf("%d%d%d%d",&x,&y,&a,&b);
if(x<y)swap(x,y);//x>=y
if(2*a<b)sum+=(LL)a*(x+y);
else{
sum+=(LL)y*b;
sum+=(LL)(x-y)*a;
}
printf("%lld\n",sum);
}
return 0;
}