Bucharest, Romania 2013 a Russian dolls greedy

Source: Internet
Author: User

A Russian toy is called a doll. A large doll can only be nested with a doll smaller than its internal size, giving you the internal volume and external volume of each doll, the consumption of empty volume in each package requires you to make the minimum cost.

Solution: here we know that it is the best option to spend the most time and fill it out.

Solution code:

1 // file name: 12895.cpp 2 // Author: darkdream 3 // created time:, Saturday, August 16, 2014, 4, 5, 5, # include <vector> 6 # include <list> 7 # include <map> 8 # include <set> 9 # include <deque> 10 # include <stack> 11 # include <bitset> 12 # include <algorithm> 13 # include <functional> 14 # include <numeric> 15 # include <utility> 16 # include <sstream> 17 # include <iostream> 18 # include <iomanip> 19 # include <cstdio> 20 # include <cmath> 21 # include <cstdlib> 22 # include <cstring> 23 # include <ctime> 24 # define ll long long25 26 using namespace STD; 27 struct node {28 int x, y, c, OK; 29} A [1, 1005]; 30 int CMP (node A, Node B) 31 {32 return. c> B. c; 33} 34 int main () {35 int N; 36 while (scanf ("% d", & N )! = EOF) 37 {38 memset (A, 0, sizeof (a); 39 for (INT I = 1; I <= N; I ++) 40 {41 scanf ("% d", & A [I]. x, & A [I]. y, & A [I]. c); 42 A [I]. OK = 1; 43} 44 sort (a + 1, A + 1 + N, CMP); 45 ll ans = 0; 46 for (INT I = 1; I <= N; I ++) 47 {48 int site = 0; 49 int MX = 0; 50 for (Int J = 1; j <= N; j ++) 51 {52 if (a [J]. OK & A [I]. y> A [J]. x) 53 {54 if (a [J]. x> MX) 55 {56 MX = A [J]. x; 57 site = J; 58} 59} 60} 61 If (SITE) 62 {63 A [site]. OK = 0; 64} 65 ans + = (a [I]. y-mx) * A [I]. c; 66} 67 printf ("% i64d \ n", ANS); 68} 69 return 0; 70}
View code

 

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.