Problem G.Giant Screen
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/G
Description
You are working in Advanced Computer Monitors (ACM), Inc. The company is building and selling giant computer screens that are composed from multiple smaller screens. Your are responsible for design of the screens for your customers. Customers order screens of the specified horizontal and vertical resolution in pixels and a specified horizontal and vertical size in millimeters. Your task is to design a screen that has a required resolution in each dimension or more, and has required size in each dimension or more, with a minimal possible price. The giant screen is always built as a grid of monitors of the same type. The total resolution, size, and price of the resulting screen is simply the sum of resolutions, sizes, and prices of the screens it is built from. You have a choice of regular monitor types that you can order and you know their resolutions, sizes, and prices. The screens of each type can be mounted both vertically and horizontally, but the whole giant screen must be composed of the screens of the same type in the same orientation. You can use as many screens of the chosen type as you need
Input
The first line of the input file contains four integer numbers rh, rv, sh, and sv (all from 100 to 10 000 inclusive) — horizontal and vertical resolution and horizontal and vertical size of the screen you have to build, respectively. The next line contains a single integer number n (1 ≤ n ≤ 100) — the number of different screen types available to you. The next n lines contain descriptions of the available screen types. Each description occupies one line and consists of five integer numbers — rh,i, rv,i, sh,i, sv,i, pi (all from 100 to 10 000 inclusive), where first four numbers are horizontal and vertical resolution and horizontal and vertical size of i-th screen type, and pi is the price.
Output
Write to the output file a single integer — the minimal price of the specified giant screen.
Sample Input
1024 1024 300 300
3
1024 768 295 270 200
1280 1024 365 301 250
1280 800 350 270 210
Sample Output
250
HINT
题意
给你一个需要的屏幕分辨率和长宽
然后给你n个,让你挑选一种,让你花费最小的价格来达到规定的电视
题解:
水题,直接贪心除一下然后取min就吼了
代码:
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <stack> #include <map> #include <set> #include <queue> #include <iomanip> #include <string> #include <ctime> #include <list> typedef unsigned char byte; #define pb push_back #define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0) #define local freopen("in.txt","r",stdin) #define pi acos(-1) using namespace std; const int maxn = 100 + 15; int rh , rv , sh , sv , n; typedef struct data { int rh , rv , sh , sv , p; }; int Caculate(int x,int y) { int num = x / y; if (y * num < x) num ++; return num; } data A[maxn]; int main(int argc,char *argv[]) { freopen("giant.in","r",stdin); freopen("giant.out","w",stdout); scanf("%d%d%d%d%d",&rh,&rv,&sh,&sv,&n); for(int i = 0 ; i < n ; ++ i) scanf("%d%d%d%d%d",&A[i].rh,&A[i].rv,&A[i].sh,&A[i].sv,&A[i].p); long long ans = 1LL << 60; for(int i = 0 ; i < n ; ++ i) { int s1 = max(Caculate(rh,A[i].rh) , Caculate(sh,A[i].sh)); int s2 = max(Caculate(rv,A[i].rv),Caculate(sv,A[i].sv)); ans = min(ans ,1LL * (long long) s1 * (long long)s2 * (long long)A[i].p ); s1 = max(Caculate(rh,A[i].rv) , Caculate(sh,A[i].sv)); s2 = max(Caculate(rv,A[i].rh),Caculate(sv,A[i].sh)); ans = min(ans ,1LL * (long long) s1 * (long long)s2 * (long long)A[i].p ); } cout << ans <<endl; return 0; }