Test instructions: give you an infinite number of columns and some values other than 0, you can do two things.
1) All values greater than 1 in the sequence are reduced by 1
2) Remove any value from a[i] to any person.
Ask you how many steps you can take at least to make the sequence all 0.
Problem Solving: Enumerate the largest a[i]. The parts larger than a[i] are divided.
Problem Solving Code:
1 //File name:b.cpp2 //Author:darkdream3 //Created time:2015 April 11 Saturday 23:16 58 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - - using namespacestd; - intT; - intN; in inta[1005]; - intMain () { toFreopen ("b-large.in","R", stdin); +Freopen ("Output","W", stdout); -scanf"%d",&t); the for(intCA =1; CA <= t; CA + +) * { $scanf"%d",&n);Panax Notoginseng intMX =0 ; - for(intI=1; I <=n;i + +){ thescanf"%d",&a[i]); +MX =Max (mx,a[i]); A } the intAns =1e9; + - for(inti =1; I <= MX; i + +){ $ intsum =i; $ for(intj =1; J <= N;j + +) - { - if(A[j] >i) the { - if(A[j]% i = =0 )Wuyi { theSum + = a[j]/i-1; -}ElseSum + = a[j]/i; Wu } - } AboutAns =min (sum,ans); $ } -printf"Case #%d:%d\n", Ca,ans); - } - return 0; A}
View Code
Google Code Jam Qualification Round B enumeration + greedy