Codeforces Gym 100269G Garage 数学
題目連接:
http://codeforces.com/gym/100269/attachments
Description
Wow! What a lucky day! Your company has just won a social contract for building a garage complex.
Almost all formalities are done: contract payment is already transferred to your account.
So now it is the right time to read the contract. Okay, there is a sandlot in the form of W × H rectangle
and you have to place some garages there. Garages are w × h rectangles and their edges must be parallel
to the corresponding edges of the sandlot (you may not rotate garages, even by 90?
). The coordinates of
garages may be non-integer.
You know that the economy must be economical, so you decided to place as few garages as possible.
Unfortunately, there is an opposite requirement in the contract: placing maximum possible number of
garages.
Now let’s see how these requirements are checked. . . The plan is accepted if it is impossible to add a new
garage without moving the other garages (the new garage must also have edges parallel to corresponding
sandlot edges).
Accepted optimal plan Rejected plan Accepted, but non-optimal plan
Time is money, find the minimal number of garages that must be ordered, so that you can place them
on the sandlot and there is no place for an extra garage.
Input
The only line contains four integers: W, H, w, h — dimensions of sandlot and garage in meters. You may
assume that 1 ≤ w ≤ W ≤ 30 000 and 1 ≤ h ≤ H ≤ 30 000.
Output
Output the optimal number of garages.
Sample Input
15 7 4 2
Sample Output
4
Hint
題意
現在給你一個矩形,W*H的,然后問你最少個w*h的小矩形
題解:
想一想
一個小矩形最多可以占據2*w*2*h的空間嘛
然后我們直接暴力算就好了,注意最后如果還有空位的話,就直接放一個進去就好了
代碼
#include<bits/stdc++.h> using namespace std;int main() {freopen("garage.in","r",stdin);freopen("garage.out","w",stdout);long long W,H,w,h;cin>>W>>H>>w>>h;long long L,R,l,r;L = W/w/2+W/w%2;R = H/h/2+H/h%2;cout<<L*R<<endl; }轉載于:https://www.cnblogs.com/qscqesze/p/5199553.html
總結
以上是生活随笔為你收集整理的Codeforces Gym 100269G Garage 数学的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转]Teach Yourself Pr
- 下一篇: [Leetcode]-containsN