POJ2100 Graveyard design 尺取

题目大意为给定N<=1e14,找连续的正整数使其平方和等于N

简单的尺取即可,一次超时忘记给l,r定成longlong,导致循环跳不出来

#include
#include
int main()
{
  long long n;
  while (scanf("%lld",&n)!=EOF)
  {
     int i,left[3000],right[3000],team=0,j;
     long long sum=0,l=1,r=0;
     while (1)
     {
       while (sumsqrt(n*1.0)) break;
       if (sum==n)
        {
          team++;
          left[team]=l;
          right[team]=r;
        }
       sum-=l*l;l++;
     }
     printf("%d\n",team);
     for (i=1;i<=team;i++)
     {
      printf("%d",right[i]-left[i]+1);
      for (j=left[i];j<=right[i];j++) printf(" %d",j);
      printf("\n");
     }
  }
}



你可能感兴趣的:(POJ2100 Graveyard design 尺取)