UVa 10970 Big Chocolate (想一下就AC了)

题意:给你一个m*n的巧克力,让人把它切成1*1的,但是每次只能切一下,问要切多少刀。

析:简单啊,我就不明白了 怎么那么多人TLE了,不会当DP做了吧,其实不用的。

假设有一个1*m的巧克力,很明显知道是切m-1刀,那么再把n把变成1,要n-1刀,加起来就OK。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int n, m;
    while(~scanf("%d %d", &n, &m)){
        printf("%d\n", n-1 + n * (m-1));
    }
    return 0;
}
时间: 2024-07-30 16:02:45

UVa 10970 Big Chocolate (想一下就AC了)的相关文章

UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

课程好紧啊,只能刷点水题了,几乎都是贪心. UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { int n,kas = 0; while(scanf("%d",&n),n>0){ int r = 0; for(n--;n;n>>=1) r++; printf("Case %d: %d\n",++kas,r); }

UVa 1009 Sharing Chocolate (数位dp)

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3540 题目大意: 给一块长x,宽y的巧克力,和一个数组A={a1, a2, …,an},问能否经过若干次切分后,得到面积分别为a1,a2,…an的n块巧克力.每次切分只可以选择一块巧克力,将其分为两半,如下图,3×4的巧克力经过切分后,可以得到面积分别为6,3,2,1的巧克力.

UVA 11468(Substring-AC自动机上dp)[Template:AC自动机]

Substring Given a set of pattern strings, and a text, you have to find, if any of the pattern is a substring of the text. If any of the pattern string can be found in text, then print "yes", otherwise "no" (without quotes). But, unfort

UVa 132 Another Chocolate Maniac(状压DP)

132. Another Chocolate Maniac time limit per test: 0.25 sec. memory limit per test: 4096 KB Bob really LOVES chocolate. He thinks he never gets enough. Imagine his joy when his parents told him that they would buy him many rectangular chocolate piece

UVa 10970 大块巧克力

https://vjudge.net/problem/UVA-10970 题意: 把一个m行n列的矩形巧克力切成mn个1×1的方块,需要切几刀. 思路: 可以考虑用动态规划的方法去做,当然,最简单的是直接找到规律,直接计算出来. 1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 #include<cstring> 5 using namespace std; 6 7 int n,

10970 - Big Chocolate

题意 :已知n*m的巧克力,问需要掰多少次能让巧克力成为最小的一块: 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int n,m; 6 while(cin>>n>>m) 7 cout<<n*m-1<<endl; 8 return 0; 9 }

AC自动机总结及板子

蒟蒻最近想学个AC自动机简直被网上的板子搞疯了,随便点开一个都是带指针的,然而平时用到指针的时候并不多,看到这些代码也完全是看不懂的状态.只好在大概理解后自己脑补(yy)了一下AC自动机的代码,居然还过了,这里对学到的东西做一点小小的总结.顺便造福一下跟我之前一样没有学过AC自动机并且不会用指针的Oier,给出一段不带指针的板子. AC自动机的模型很好理解,就是在Trie树上做类似于KMP的操作.所以说在AC自动机里也会有一个类似于 next 数组的东西------ fail 数组来作为失配指针

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

大白书

UVA 11292 (简单贪心) 题意: n条恶龙,m个勇士,用勇士来杀恶龙.一个勇士只能杀一个恶龙.而且勇士只能杀直径不超过自己能力值的恶龙.每个勇士需要支付能力值一样的金币.问杀掉所有恶龙需要的最少金币. 思路: 贪心,均从小到大排序.为每一条龙找一个恰好能杀他的骑士.简单贪心. UVA 11729 (经典贪心问题) 题意: n个任务,需要交代B分钟,执行J分钟,让你合理选择交代任务的次序,求得n个任务完成的最小总时长. 思路: 经典贪心,通过比较俩俩的关系,得到整个序列的贪心排序方法.这个