HDU 4982 Goffi and Squary Partition

Source: Internet
Author: User

HDU 4982 Goffi and Squary Partition

Link: HDU 4982 Goffi and Squary Partition

Given n and k, and for a number of workers K-1 each different number, plus a number (This number is also different from the number of k-1), their sum is equal to n, determine whether such a sequence exists.

Idea: enumerate the number of workers. Of course, constructing the smallest sequence starts from 1.




AC code:

# Include
 
  
Int k, n; bool judge (int sum, int lef) // sum the K-1 before sum, and lef is left. Sum + lef = n {if (lef = 0 | 2 * sum <(k-1) * k) return false; if (sum = 1 & lef = 1) return false; int x, ss; // ss is the first K-2 item and ss = 0, x = 0; for (int I = 0; I
  
   
Xx ++; // change the value of the K-2 item // The Front K-2 is closely arranged if (k-1), (K-2), lef is equal, at least two locations must be moved to meet the requirements. If (temp = x & temp = lef) // K-2 item + 1 equals K-1 item equals lefreturn false; if (temp = x + 1 & temp = lef) // K-2 item + 2 equals K-1 item equals lefreturn false; return true;} int main () {int I; int lef; while (scanf ("% d", & n, & k )! = EOF) {int flag = 0; for (I = 1; I * I <= n; I ++) {lef = n-I * I; if (judge (I * I, lef) break;} if (I * I <= n) printf ("YES \ n "); elseprintf ("NO \ n");} return 0 ;}
  
 


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.