POJ2100 Graveyard Design (ruler)

Source: Internet
Author: User

POJ2100 Graveyard Design

Topic: Given a number n, the sum of the squares of a continuous positive integer equals n, and output these schemes, pay attention to the output format;

The cyclic judging condition can be properly cut, improve the efficiency, (1^2+2^2+). n^2) =n* (n+1) * (2n+1)/6;

It is important to pay attention to the judgment of the cyclic termination condition when the ruler is taken.

    

#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<string>#include<vector>#include<deque>#include<list>#include<Set>#include<map>#include<stack>#include<queue>#include<numeric>#include<iomanip>#include<bitset>#include<sstream>#include<fstream>using namespacestd;#defineRep (i,a,n) for (int i=a;i<n;i++)#definePer (i,a,n) for (int i=n-1;i>=a;i--)#defineIn (n) scanf ("%d",& (n))#defineIn2 (X1,X2) scanf ("%d%d",& (x1),& (x2))#defineINLL (n) scanf ("%i64d",& (n))#defineInll2 (X1,X2) scanf ("%i64d%i64d",& (x1),& (x2))#defineINLLD (n) scanf ("%lld",& (n))#defineInlld2 (X1,X2) scanf ("%lld%lld",& (x1),& (x2))#defineINF (n) scanf ("%f",& (n))#defineInf2 (X1,X2) scanf ("%f%f",& (x1),& (x2))#defineINLF (n) scanf ("%lf",& (n))#defineINLF2 (X1,X2) scanf ("%lf%lf",& (x1),& (x2))#defineInc (STR) scanf ("%c",& (str))#defineINS (str) scanf ("%s", (str))#defineOut (x) printf ("%d\n", (x))#defineOut2 (x1,x2) printf ("%d%d\n", (x1), (x2))#defineOutf (x) printf ("%f\n", (x))#defineOUTLF (x) printf ("%lf\n", (x))#defineOUTLF2 (x1,x2) printf ("%lf%lf\n", (x1), (x2));#defineOUTLL (x) printf ("%i64d\n", (x))#defineOUTLLD (x) printf ("%lld\n", (x))#defineOUTC (str) printf ("%c\n", (str))#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#defineSZ (x) ((int) (x). Size ())#defineMem (x, y) memset (x,y,sizeof (×));typedef vector<int>Vec;typedefLong LongLl;typedef pair<int,int>P;Const intdx[4]={1,0,-1,0},dy[4]={0,1,0,-1};Const intinf=0x3f3f3f3f;Constll mod=1e9+7; ll Powmod (ll A,ll b) {ll res=1; a%=mod; for(; b;b>>=1){if(b&1) Res=res*a%mod;a=a*a%mod;}returnRes;}Const BOOLAc=true;structnode{ll Num,a,b;}; Node p[100000];BOOLCMP (node X,node y) {returnX.num>Y.num;}intMain () {ll n,s,t,sum,k,cnt;//are set to Longlong lest overflow     while(INLL (n)! =EOF) {s=t=1; sum=0; k=0;  while(true){             while(sum<n) {//Notice the loop termination conditionsum+=t*T; T++; }            if(sum==N) {p[k].num=t-s; P[K].A=s; P[k++].b=t-1; } Sum-=s*s; S++; if(s*s>n) Break;//Notice the loop termination condition} CNT=K; printf ("%i64d\n", CNT);//don't forget this.Sort (p,p+k,cmp); Rep (I,0, K) {printf ("%i64d", P[i].num);  for(LL j=p[i].a;j<=p[i].b;j++) {printf ("%i64d", J); } printf ("\ n"); }    }    return 0;}

POJ2100 Graveyard Design (ruler)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.