Background: Think for a long time only thought with deep search index level enumeration method to over the small data, big Data natural timeout, later read the report, before.
idea: There are n pancakes on the plate with the largest number of pancakes on all plates, I from 1 ... n enumerate the number of pancakes after splitting, and then use the greedy method to calculate the minimum number of split steps required to reach the current state K, the last time is i + K, to find out all the time of the smallest can
sentiment: The essence of this problem is that all final state up to only 1000, for each final state of the required steps can be obtained through efficient greedy method, thinking is very clever, is a violent enumeration and the ingenious combination of greed.
My Code:
#include <cstdio>#include <iostream>#include <cmath>#include <cstring>#include <algorithm>using namespace STD;BOOLcmpintAintb) {returna > B;}intMainvoid) {//freopen ("b-large-practice.in", "R", stdin); //freopen ("B-large-practice.out", "w", stdout); intT, N, pancake[1009], ans, key;scanf("%d", &t); for(intK =1; K <= T; k++) {scanf("%d", &n); for(inti =0; I < n; i++)scanf("%d", &pancake[i]); Sort (pancake, pancake + N, CMP);if(pancake[0] <=3)printf("Case #%d:%d\n", K, pancake[0]);Else{ans = pancake[0]; for(inti = pancake[0] -1; I >=1; i--) {key = i; for(intj =0; J < n && Pancake[j] > i; J + +) {key + =Ceil((Double) Pancake[j]/i)-1; }if(Key < ans) ans = key; }printf("Case #%d:%d\n", k, ans); } }return 0;}
Google Codejam Qualification Round B Clever enumeration results + greedy