UVa 10970 大块巧克力
2024-08-28 08:32:47
https://vjudge.net/problem/UVA-10970
题意:
把一个m行n列的矩形巧克力切成mn个1×1的方块,需要切几刀。
思路:
可以考虑用动态规划的方法去做,当然,最简单的是直接找到规律,直接计算出来。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std; int n, m;
int d[][]; int dp(int i, int j)
{
int& ans = d[i][j];
if (ans != -) return ans;
if (i == ) return ans=j - ;
if (j == ) return ans=i - ;
if (i % == ) ans = * dp(i / , j) + ;
else if (j % == ) ans = * dp(i, j / ) + ;
else return ans = dp(i - , j) + j;
} int main()
{
ios::sync_with_stdio(false);
//freopen("D:\\txt.txt", "r", stdin);
while (cin >> n >> m)
{
memset(d, -, sizeof(d));
dp(n, m);
cout << d[n][m] << endl;
}
}
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std; int n, m; int main()
{
ios::sync_with_stdio(false);
//freopen("D:\\txt.txt", "r", stdin);
while (cin >> n >> m)
{
cout << m*n - << endl;
}
}
最新文章
- 使用Visual Studio SDK制作GLSL词法着色插件
- Docker命令学习
- 微信 {";errcode";:48001,";errmsg";:";api unauthorized, hints: [ req_id: 1QoCla0699ns81 ]";}
- [暴力搜索] POJ 3087 Shuffle&#39;m Up
- [2014.01.27]WFsoft.wfWebCtrl.wfPage 5.9
- Linux系统MySQL开启远程连接
- Hadoop 之Impala
- HTTP 错误 500.21 - Internal Server Error 处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- 如何在TFS的过程模板中添加报表
- 基本Socket通信流程
- android 存储概念
- LA 3983 Robotruck
- 获取枚举Description的Name
- git推送本地分支到远端 以及删除远端分支的 命令
- vuex 模块
- HashMap和HashTable 学习
- 1.3 selenium IDE录制脚本转换为其他代码格式
- ionic2+Angular2:套接口明细步骤,以登录功能为例
- [转] babel 教程
- 【Python】print array时array中间是省略号没有输出全部的解决方法
热门文章
- MySQL IFNULL()函数用法MySQL
- 飞跃平野(sdut1124)
- 【Cocos2dx 3.3 Lua】剪裁结点ClippingNode
- [LeetCode] 429. N-ary Tree Level Order Traversal_ Easy
- [LeetCode] questions conclustion_Path in Tree
- gcc升级
- [转]autoid文件上传
- 页面点击,不是a标签也会刷新原因
- centos 网卡名称修改
- oracle中验证身份证是否合法的函数脚本