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 ;}