Graveyard
Given an integer, I want you to find out his squared and combination.
It's too easy .... But at first I stored the square and wanted to reduce the time, later found to be super memory, direct use of time to change space, vernier caliper method
1#include <iostream>2#include <functional>3#include <algorithm>4 #defineMax_n 100000015 6 using namespacestd;7typedefLong LongLl_int;8 9 Static intstore[max_n][2];//save start and end onlyTen One voidInivilize (void); A - intMainvoid) - { the ll_int N, SUM, tmp; - ints, T, num; - - while(~SCANF ("%lld", &N)) + { -sum = num =0; s = t =1; + while(1) A { at while(TMP = (ll_int) t* (ll_int) t) <= n && Sum <N) - { -Sum + =tmp; -t++; - } - if(Sum = =N) in { -store[num][0] = s; store[num][1] =T; tonum++; + } - if(Sum <N) the Break; *Sum-= (ll_int) s* (ll_int) s; s++; $ }Panax Notoginsengprintf"%d\n", num); - for(inti =0; i < num; i++) the { +printf"%d", store[i][1]-store[i][0]); A for(intj = store[i][0]; J < store[i][1]; J + +) theprintf"%d", j); +printf"\ n"); - } $ } $ returnexit_success; -}
Greedy:graveyard Design (POJ 2100)