zoukankan      html  css  js  c++  java
  • Codeforces 450C:Jzzhu and Chocolate(贪心)

    C. Jzzhu and Chocolate

    time limit per test: 1 seconds
    memory limit per test: 256 megabytes
    input: standard input
    output: standard output

    Jzzhu has a big rectangular chocolate bar that consists of (n × m) unit squares. He wants to cut this bar exactly (k) times. Each cut must meet the following requirements:

    • each cut should be straight (horizontal or vertical);
    • each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
    • each cut should go inside the whole chocolate bar, and all cuts must be distinct.

    The picture below shows a possible way to cut a (5 × 6) chocolate for (5) times.

    Imagine Jzzhu have made (k) cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly (k) cuts? The area of a chocolate piece is the number of unit squares in it.

    Input

    A single line contains three integers (n, m, k (1 ≤ *n*, *m* ≤ 10^9; 1 ≤ k ≤ 2·10^9)).

    Output

    Output a single integer representing the answer. If it is impossible to cut the big chocolate (k) times, print (-1).

    input

    3 4 1
    

    output

    6
    

    input

    6 4 2
    

    output

    8
    

    input

    2 3 4
    

    output

    -1
    

    Note

    In the first sample, Jzzhu can cut the chocolate following the picture below:

    In the second sample the optimal division looks like this:

    In the third sample, it's impossible to cut a (2 × 3) chocolate (4) times.

    题意

    给出一个(n imes m)大小的巧克力,巧克力有(n imes m)个格子,要求切(k)刀之后,使切得的最小的方块面积最大,求这个最小的面积

    思路

    贪心

    每次切的时候先尽可能的朝着一个方向切,切完之后在考虑另外那个方向,切得时候注意要平均切。然后比较首先横向切和首先纵向切的最大值

    注意当(k>n+m-2)的情况是无法切的

    代码

    #include <bits/stdc++.h>
    #define ll long long
    #define ull unsigned long long
    #define ms(a,b) memset(a,b,sizeof(a))
    const int inf=0x3f3f3f3f;
    const ll INF=0x3f3f3f3f3f3f3f3f;
    const int maxn=1e6+10;
    const int mod=1e9+7;
    const int maxm=1e3+10;
    using namespace std;
    ll solve(ll n,ll m,ll k)
    {
    	if(n>k)
    		return n/(k+1)*m;
    	k-=(n-1);
    	return m/(k+1);
    }
    int main(int argc, char const *argv[])
    {
        #ifndef ONLINE_JUDGE
            freopen("/home/wzy/in", "r", stdin);
            freopen("/home/wzy/out", "w", stdout);
            srand((unsigned int)time(NULL));
        #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll n,m,k;
        cin>>n>>m>>k;
        if(k>n+m-2)
        	cout<<-1<<endl;
        else
        	cout<<max(solve(n, m, k),solve(m,n,k));
        #ifndef ONLINE_JUDGE
            cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
        #endif
        return 0;
    }
    
  • 相关阅读:
    App.js和App.css(用于移动应用的js和css)
    cookie和session使用
    html实现返回上一页的几种方法(javaScript:history.go(-1);)
    sublime找到成对标签(Ctrl+Shift+")
    Java NIO框架Netty课程(一) – Hello Netty
    信息增益的特征选择方法
    Java线程学习笔记(两) 线程异常处理
    薏米红豆粥的功效和实践演示
    文件翻译002片:Process Monitor帮助文档(Part 2)
    Spring MVC 3 深入总结
  • 原文地址:https://www.cnblogs.com/Friends-A/p/11656202.html
Copyright © 2011-2022 走看看