题解 P2773 【漂亮字串】
Water_Cows · · 题解
这题其实很简单
这题直接分类讨论。
1. 有0的时候
-
有一方为0,则结果为另一方的
max ; -
两方都为0,则结果为0;
2. 不够用的一方即使每次只取一个作为分隔符都不够用
什么意思??
-
当
X 不够时-
代码
ans=(countx+1)*maxo+countx-
例子
输入:5 100 2 2
最长的超级优美无敌串为:
XXOXXOXXOXXOXXOXX
-
-
-
当
O 不够时-
代码
ans=(counto+1)*maxx+counto- 例子
输入:20 5 3 2
最长的超级优美无敌串为:
OOOXOOOXOOOXOOOXOOOXOOO
-
3. 另外
-
ans=maxn+maxm
然后就是代码环节
code
#include <cstdio>
using namespace std;
long long X, Y, A, B;//注意long long
inline long long min(long long x, long long y) {return x<y? x:y;}
int main()
{
while(scanf("%lld%lld%lld%lld", &X, &Y, &A, &B)!=EOF)
{
A=min(X, A);
B=min(Y, B);
//注意取最小
if(A==0) printf("%lld\n", B);
else if(B==0) printf("%lld\n", A);
//第一种
else if((X+1)*B<Y) printf("%lld\n", (X+1)*B+X);
else if((Y+1)*A<X) printf("%lld\n", (Y+1)*A+Y);
//第二种
else printf("%lld\n", X+Y);
//第三种
}
return 0;
so beautiful
}
PS. 这里用A,B,X,Y代替了上面的那些变量,不影响理解
我的第一篇题解,求管理员大大通过