记录编号 |
21005 |
评测结果 |
AAAAAAAAAA |
题目名称 |
漂亮字串 |
最终得分 |
100 |
用户昵称 |
苏轼 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.095 s |
提交时间 |
2010-11-02 11:35:48 |
内存使用 |
0.27 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int main()
{
freopen("bs.in","r",stdin);
freopen("bs.out","w",stdout);
LL maxo,maxx;
LL counto,countx;
while(cin>>counto>>countx>>maxo>>maxx)
{
if (counto>countx)
{
swap(counto,countx);
swap(maxo,maxx);
}
//special
if (maxo==0&&maxx==0)
{
cout<<0<<endl;
continue;
}
if (maxo==0||maxx==0)
{
cout<<min(maxo,counto)+min(maxx,countx)<<endl;
continue;
}
if (counto==0&&countx==0)
{
cout<<0<<endl;
continue;
}
if (counto==0||countx==0)
{
cout<<min(counto,maxo)+min(maxx,countx)<<endl;
continue;
}
//usual
if (counto==countx)
{
cout<<counto+countx<<endl;
continue;
}
LL groupo=counto,groupx=groupo+1;
LL eacho=counto/groupo,eachx=countx/groupx;
LL lefto=counto-eacho*groupo,leftx=countx-eachx*groupx;
LL cano=(maxo-eacho)*groupo,canx=(maxx-eachx)*groupx;
LL re=eacho*groupo+eachx*groupx+
min(cano,lefto)+min(canx,leftx);
cout<<re<<endl;
}
return 0;
}