A. Another One Bites The Dust
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have a strings “a”, b strings “b” and c strings “ab”. You want to choose some subset of these strings and concatenate them in any arbitrarily order.
What is the length of the longest good string you can obtain this way?
Input
The first line contains three positive integers a, b, c (1≤a,b,c≤109) — the number of strings “a”, “b” and “ab” respectively.
Output
Print a single number — the maximum possible length of the good string you can obtain.
Examples
input
1 1 1
output
4
input
2 1 2
output
7
input
3 5 2
output
11
input
2 2 1
output
6
input
1000000000 1000000000 1000000000
output
4000000000
Note
In the first example the optimal string is “baba”.
In the second example the optimal string is “abababa”.
In the third example the optimal string is “bababababab”.
In the fourth example the optimal string is “ababab”.
水题:
题意:
输入三个数分别是a的数量,b的数量,ab的数量,然后变成ababab,abababa或bababab这种最长是多少。
思路:
最后一个可以不用管,因为他铁定是可以排进去的因为它是ab形式,它们自己不管怎么排都是good字符串,然后看a的数量和b的数量,可以凑成几个ab,然后看ababab这种形式可以第一个a前面放个b,最后一个b后面可以放个a,那么a的数量和b的数量不相等,就可以总数加1。
操作
那么最后一个可以直接乘2加进sum,然后sum加上a的数量和b的数量的最小值乘2,然后看a的数量和b的数量是否相等,不相等sum加1。
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<sstream>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std;
int main(){
std::ios::sync_with_stdio(false);
ll a,b,c;
while(cin>>a>>b>>c){
ll sum=c*2;//最后一个可以直接乘2加进sum
sum+=min(a,b)*2;//sum加上a的数量和b的数量的最小值乘2
if(a!=b)sum++;//看a的数量和b的数量是否相等,不相等sum加1
cout<<sum<<endl;
}
}