Educational Codeforces Round 86 (Rated for Div. 2)(A&&B)

Road To Zero CodeForces - 1342A
You are given two integers x and y. You can perform two types of operations:

Pay a dollars and increase or decrease any of these integers by 1. For example, if x=0 and y=7 there are four possible outcomes after this operation:
x=0, y=6;
x=0, y=8;
x=−1, y=7;
x=1, y=7.
Pay b dollars and increase or decrease both integers by 1. For example, if x=0 and y=7 there are two possible outcomes after this operation:
x=−1, y=6;
x=1, y=8.
Your goal is to make both given integers equal zero simultaneously, i.e. x=y=0. There are no other requirements. In particular, it is possible to move from x=1, y=0 to x=y=0.

Calculate the minimum amount of dollars you have to spend on it.

Input
The first line contains one integer t (1≤t≤100) — the number of testcases.

The first line of each test case contains two integers x and y (0≤x,y≤109).

The second line of each test case contains two integers a and b (1≤a,b≤109).

Output
For each test case print one integer — the minimum amount of dollars you have to spend.

Example
Input
2
1 3
391 555
0 0
9 4
Output
1337
0
Note
In the first test case you can perform the following sequence of operations: first, second, first. This way you spend 391+555+391=1337 dollars.

In the second test case both integers are equal to zero initially, so you dont’ have to spend money.
思路:如果2*a<=b的话,就用第一种方法;否则共同的那一部分用b,多于的那一部分用a。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

ll x,y,a,b;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		cin>>x>>y>>a>>b;
		if(x==y&&x==0) cout<<0<<endl;
		else
		{
			if(a*2<=b) cout<<(x+y)*a<<endl;
			else cout<<min(x,y)*b+(max(x,y)-min(x,y))*a<<endl;
		}
	}
	return 0;
}

Binary Period CodeForces - 1342B
思路:在2*t范围内,我们可以构造出101010…这样的串的,所以k如果不是1的话,那就是2.先检测一下原来的串是否只由一种元素构成,如果不是那就构造出10101010…这样的。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

string s;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		cin>>s;
		int flag=1;
		for(int i=1;i<s.length();i++)
		{
			if(s[i]!=s[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag) cout<<s<<endl;
		else 
		{
			for(int i=0;i<2*s.length();i++)
			{
				if(i%2==0) cout<<1;
				else cout<<0;
			}
			cout<<endl;
		}
	}
	return 0;
}

努力加油a啊,(o)/~

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值