这题WA了一上午,最后找特判,想了好久竟然没有想到sc=1的特判情况,也是醉了,加了个特判分分钟AC了
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<set>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
#include<memory>
#include<climits>
using namespace std;
#define LL long long
#define INT (1<<31)-1
const int maxn=1000;
const double eps=1e-12;
int dcmp(double x)
{
if(fabs(x)<eps)
return 0;
else
return x>0?1:-1;
}
int main()
{
int h,sc;
while(cin>>h>>sc)
{
if(h==0&&sc==0) break;
int nw=0,sh=0;
int i,x;
if(sc==1)
{
nw=log(h)/log(2);
sh=2*h-1;
}
else
{
for(i=1;i<10000;i++)
{
if(h%(i+1)==0&&sc%i==0&&dcmp(log10(h)/log10(1+i)-log10(sc)/log10(i))==0)
{
break;
}
}
nw=(sc-1)/(i-1);
sh=h*(i+1)-sc*i;
}
cout<<nw<<' '<<sh<<endl;
}
return 0;
}

本文分享了一个ACM编程挑战赛中的题目解析过程,重点介绍了如何通过特判处理来解决特定输入条件下的问题。文章详细展示了当输入参数为1时的特殊情况,并给出了一段C++代码实现,该代码能够正确处理一般情况与特判情况。
1万+

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



