Google Codejam Qualification Round B Clever enumeration results + greedy

Source: Internet
Author: User

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

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.