Greedy:graveyard Design (POJ 2100)

Source: Internet
Author: User

              

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)

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.