cf 450c Jzzhu and Chocolate
2016-05-09 15:06
513 查看
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 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.
View Code
我感觉这道题是一种很巧妙的暴力,枚举可能的四种情况,取最大值。
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 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.
#include<iostream> #include<stdio.h> using namespace std; int main() { long long n,m,k; while(~scanf("%I64d%I64d%I64d",&n,&m,&k)) { if(n>=k+1||m>=k+1) { long long maxx=max(n,m); long long minn=min(n,m); long long cl1=minn/(1+k); long long cl2=maxx/(1+k); //cout<<minn<<endl<<maxx<<endl<<cl1<<endl<<cl2<<endl; long long tmpma=0; long long tmpmi=0; tmpmi=maxx*cl1; tmpma=minn*cl2; long long ans=max(tmpmi,tmpma); if(ans>0) printf("%I64d\n",ans); //printf("%I64d\n",maxx/(k+1)*minn); continue; } long long minn=min(n,m); long long maxx=max(n,m); long long cl1=k-minn+1; long long cl2=k-maxx+1; //cout<<minn<<endl<<maxx<<endl<<cl1<<endl<<cl2<<endl; long long tmpma=0; long long tmpmi=0; if(cl1<maxx) tmpmi=maxx/(cl1+1); if(cl2<minn) tmpma=minn/(cl2+1); long long ans=max(tmpmi,tmpma); if(ans>0) printf("%I64d\n",ans); else printf("-1\n"); } return 0; }//20180805
View Code
我感觉这道题是一种很巧妙的暴力,枚举可能的四种情况,取最大值。
相关文章推荐
- 设计模式读书笔记-----单例模式
- 如何利用github打造博客专属域名
- RecycleView初尝试
- 18. 带重复元素的子集
- Python之for循环
- WPF 实现3维视频凸面墙
- ui-router使用方法
- php第十四节课
- ora-01190和ora-01110的解决方法
- OS X 快捷键——上篇
- 转载:Hive的安装以及使用
- html复习第七天 京东首页布局完成
- 第10,11周 项目一(2)
- 设计模式读书笔记-----原型模式
- CSS浮动 (比较详细、生动、经典)
- SQL的主键和外键约束
- 第7周 C语言程序设计(新2版) 练习1-9 输入复制到输出且多个空格用一个空格代替
- 使用Opencv的一些注意事项
- 提高数据库查询性能浅谈
- JqueryUI学习笔记-自动完成autocomplete