EQS Binary Enumeration + Two-point search for flood problems

Source: Internet
Author: User

                        Eqs

Title Abstract: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 (*), gives A1,a2,a3,a4,a5. Ai belongs to [ -50,50].

Ask how many sequences x1,x2,x3,x4,x5, Xi belongs to [ -50,50]-{0}.

Idea: Binary enumeration + binary lookup

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <map>7 using namespacestd;8typedefLong LongLL;9 Const intms= -;Ten Const intSize=10000; One  A intHash[size]; - intCNT; -  the intMain () - { -     intA1,a2,a3,a4,a5; -      while(SCANF ("%d%d%d%d%d", &AMP;A1,&AMP;A2,&AMP;A3,&AMP;A4,&AMP;A5)! =EOF) +     { -Cnt=0; +          for(inti=-ms;i<=ms;i++) A              for(intj=-ms;j<=ms;j++) at         { -             if(i==0|| j==0) -                 Continue; -             intt=a1*i*i*i+a2*j*j*J; -hash[cnt++]=T; -         } inSort (hash,hash+CNT); -         intans=0; to          for(inti=-ms;i<=ms;i++) +              for(intj=-ms;j<=ms;j++) -                  for(intk=-ms;k<=ms;k++) the         { *             if(i==0|| j==0|| k==0) $                 Continue;Panax Notoginseng             intt=a3*i*i*i+a4*j*j*j+a5*k*k*K; -Ans+=upper_bound (hash,hash+cnt,-t)-lower_bound (hash,hash+cnt,-t); the         } +printf"%d\n", ans); A     } the     return 0; +}

EQS Binary Enumeration + Two-point search for flood problems

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.