HDU 4982 Goffi and Squary Partition
Idea: directly from the total square number down, and then infer whether it can construct the total square number, assuming can be yes, assuming that all is not. Notice the inference of the construction time, because the enumeration is a total square. The remaining number is KK. Make sure the numbers don't repeat when you construct them.
Code:
#include <cstdio> #include <cstring> #include <cmath>int N, k;bool judge (int num) { int yu = num * num ; int KK = N-yu; if (KK = = 0) return false; int sum = 0; int cnt = 0; for (int i = 0; i < k-2; i++) {cnt++;if (cnt = = KK) Cnt++;sum + = cnt; } if (sum + KK >= N) return false; int need = N-SUM-KK; If (need <= CNT) return false; cnt++; if (KK = = CNT | | kk = CNT + 1) {if (need = = KK) return false; } return true;} BOOL Solve () { int m = sqrt (n * 1.0); for (int i = m; I >= 1; i--) {if (judge (i)) { return true;} } return false;} int main () {while (~scanf ("%d%d", &n, &k)) {if (Solve ()) printf ("yes\n"); else printf ("no\n"); } return 0;}
HDU 4982 Goffi and Squary Partition (inference)