http://acm.hdu.edu.cn/showproblem.php?pid=1391
#include<stdio.h>
int solve(int a,int b)
{
int s=1,i;
if(a==0)
{
if(b==0)
return 0;
return -1;
}
if(a==1)
{
if(b==1)
return 1;
return -1;
}
for(i=1;i<b;++i)
if(i&1)
s+=3;
else
s+=1;
if(a==b)
return s;
else if(a-2==b)
return s+2;
else
return -1;
}
int main()
{
int t,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
a=solve(a,b);
if(a==-1)
这篇博客详细介绍了HDU ACM竞赛中的一道简单题目1391,探讨了如何通过数学推理和算法设计解决该问题,适合初学者练习。
订阅专栏 解锁全文
264

被折叠的 条评论
为什么被折叠?



