449A - Jzzhu and Chocolate 贪心

一道贪心题,尽量横着切或竖着切,实在不行在交叉切

#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
 //   freopen("in.txt","r",stdin);
    long long n,m,k;
    while(cin>>n>>m>>k){
        if((n+m-2)<k){
            printf("-1\n");
            continue;
        }
        long long max=0,t;
        if(n>m){
            t=m;m=n;n=t;
        }
        long long ans;
        if(m>=(k+1)){
            ans=(n/(k+1)*m)>(m/(k+1)*n)?(n/(k+1)*m):(m/(k+1)*n);
        }
        else{
            ans=(m/(k-(n-1)+1))>(n/(k-(m-1)+1))?(m/(k-(n-1)+1)):(n/(k-(m-1)+1)) ;
        }
        cout<<ans<<endl;
    }
}

449A - Jzzhu and Chocolate 贪心

时间: 2024-10-28 16:17:29

449A - Jzzhu and Chocolate 贪心的相关文章

Codeforces Round #257 (Div. 2)449A - Jzzhu and Chocolate(贪心、数学)

题目链接:http://codeforces.com/problemset/problem/449/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

CodeForces 449A - Jzzhu and Chocolate

传送门:Jzzhu and Chocolate 题意: 给出一个N * M的矩阵,给K个操作,每次操作可以横/竖切割矩阵,最后求K次切割之后,矩阵最小的那块面积最大是多少? 分析: 按照题意,题目求的结果是:(最小的面积,最大是多少),那么可以想到,K次切割之后尽量使得每个块的面积相等,某些块比较大(因为不一定能平均分),那么就可以使得最小的那块面积最大了. 然后如何切割呢? 因为有横竖两个切割方法,那么我们可以设X为横切割数,Y为竖切割数,其中(0 <= X, Y <= K),因为最多对一个

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 exact

Codeforces449A Jzzhu and Chocolate &amp;&amp; 449B Jzzhu and Cities

CF挂0了,简直碉堡了.两道题都是正确的思路但是写残了.写个解题报告记录一下心路历程. A题问的是 一个n*m的方块的矩形上切k刀,最小的那一块最大可以是多少.不难发现如果纵向切k1刀,横向切k2刀,那么答案应该是 (n/(k1+1)) * (m/(k2+1)),除法是取整的.虽然是取整,但是不难发现其实就是要(k1+1)*(k2+1)最小,根据均值不等式,k1+k2=k(定值) k1==k2的时候(k1+1)*(k2+1)=k1*k2+k1+k2+1=k1*k2+k+1应该是取最大值,所以当k

(CF#257)C. Jzzhu and Chocolate

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 edg

BZOJ 2430 Poi2003 Chocolate 贪心

题目大意:给定一个巧克力,怎么切看题目吧我实在写不动了= = 首先每条线被切至少一次 在此基础上一条线每被切一次就多付出一份代价 故每个交叉点上用权值较大的线切权值较小的线比较优 说白了就是大的先切然后小的后切 贪心的证明我说不明白了大家意会吧QAQ 一天之内写了整整十道题也是够受的了QAQ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #defin

hdu 4112 Break the Chocolate 贪心

Break the Chocolate Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4112 Description Benjamin is going to host a party for his big promotion coming up.Every party needs candies, chocolates and beer, and of cour

Codeforces 450 C. Jzzhu and Chocolate

//area=(n*m)/ ((x+1)*(k-x+1)) //1: x==0; //2: x=n-1 //3: x=m-1 # include <stdio.h> long long max(long long x,long long y) { return x>y?x:y; } int main() { long long n,m,k,sum,t,ans; scanf("%lld%lld%lld",&n,&m,&k); sum=n+m-2;

Codeforces Round #257 (Div. 2)C 贪心

C. Jzzhu and Chocolate time limit per test 1 second 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 time