http://poj.org/problem?id=1190

题解:四个剪枝。

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<string>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
// ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
int n, m;
int mn = << ;
int area = ;
int mnV[];
int mnA[];
int maxVforNRH(int n, int r, int h) {
int v = ;
rep(i, , n - )
v += (r - i)*(r - i)*(h - i);
return v; }
void dfs(int v,int n,int r,int h) {//n层凑v,底层不超r,h
if (n == ) {
if (v)return;
else {
mn = min(mn, area);
return;
}
}
if (v <= )return;
if (mnV[n] > v)return;//
if (area + mnA[n] >= mn)return;//
if (h < n || r < n)return; //
if (maxVforNRH(n,r,h)< v)return;//
per(rr, r, n) {
if (n == m)area = rr*rr;
per(hh, h, n) {
area += * rr*hh;
dfs(v - rr*rr*hh, n - , rr - , hh - );
area -= * rr*hh;
}
}
}
void Run() { } void smain() { cin >> n >> m;
mnV[] = ;
mnA[] = ;
rep(i, , m) {
mnV[i] = mnV[i - ] + i*i*i;
mnA[i] = mnA[i - ] + * i*i;
}
if (mnV[m] > n)cout << << endl;
else {
int maxH = (n - mnV[m - ]) / (m*m) + ;
int maxR = sqrt(double(n - mnV[m - ]) / m) + ;//底层最大的H,R
area = ;
mn = << ;
dfs(n, m, maxH, maxR);
if (mn == << ) {
cout << << endl; }
else cout << mn << endl;
}
Run();
}

生日蛋糕 POJ - 1190 搜索 数学的更多相关文章

  1. 生日蛋糕 POJ - 1190 (搜索+剪枝)

    7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱.当 ...

  2. 洛谷 P1731 [NOI1999]生日蛋糕 && POJ 1190 生日蛋糕

    题目传送门(洛谷)  OR 题目传送门(POJ) 解题思路: 一道搜索题,暴力思路比较容易想出来,但是这道题不剪枝肯定会TLE.所以这道题难点在于如何剪枝. 1.如果当前状态答案已经比我们以前某个状态 ...

  3. 生日蛋糕 POJ - 1190

    7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱.当 ...

  4. poj 1190 DFS 不等式放缩进行剪枝

    F - (例题)不等式放缩 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submi ...

  5. catch that cow POJ 3278 搜索

    catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...

  6. POJ 1190 生日蛋糕 【DFS + 极限剪枝】

    题目传送门:http://poj.org/problem?id=1190 参考剪枝:https://blog.csdn.net/nvfumayx/article/details/6653111 生日蛋 ...

  7. POJ 1190 生日蛋糕题解

    题目地址:http://poj.org/problem?id=1190 一道很有趣的搜索题--主要是剪枝-- 我弄了5个剪枝: 1.当前剩余层数>=上层半径,剪掉 2.当前剩余层数>=上层 ...

  8. Codevs 1710 == POJ 1190 生日蛋糕 == 洛谷P1731

    生日蛋糕 时间限制: 2 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ ...

  9. 【POJ - 1190】生日蛋糕 (dfs+剪枝)

    Descriptions: 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为 ...

随机推荐

  1. SNF开发平台WinForm-审核流使用方法样例

    一.效果如下: 二.如何实现 1.程序的数据表设计规范,参考<09.SNF-C#编程规范V1.5.docx>文件. 2.程序操作程序 2.1.在程序页面拖拽控件 2.2.程序的Load事件 ...

  2. iOS画折线图

    代码例子效果:  下载地址:http://download.csdn.net/detail/qqmcy/6983187 LineChartViewDemo.h #import <UIKit/UI ...

  3. 3. RNN神经网络-LSTM模型结构

    1. RNN神经网络模型原理 2. RNN神经网络模型的不同结构 3. RNN神经网络-LSTM模型结构 1. 前言 之前我们对RNN模型做了总结.由于RNN也有梯度消失的问题,因此很难处理长序列的数 ...

  4. 【emWin】例程三十一:窗口对象——Multipage

    简介: ULTIPAGE 类似于笔记本中的分隔卡或文件柜中的标签.通过使用MULTIPAGE 小工具,应用程序可为窗口或对话框的相同区域定义多个页面.每个页面包含特定 类型的信息或用户选择相应页面时应 ...

  5. 学习MongoDB(三) Add an Arbiter to Replica Set 集群中加入仲裁节点

    Add an Arbiter to Replica Set 在集群中加入仲裁节点,当集群中主节点挂掉后负责选出新的主节点,仲裁节点也是一个mongo实力,但是它不存储数据. 1.仲裁节点消耗很小的资源 ...

  6. idea配置项目运行时内存大小

    选择 edit Configurations : -server -XX:PermSize=1024M -XX:MaxPermSize=2048M

  7. 挖坑:handoop2.6 开启kerberos(全流程学习记录)

    目录: 1.涉及插件简介 2.安装步骤 3.日志错误查看 1.kerberos是什么东西 度娘指导: Kerberos 是一种网络认证协议,其设计目标是通过密钥系统为 客户机 / 服务器 应用程序提供 ...

  8. Android KK 找不到<cutils/properties.h>

    一直通过property来控制android系统的号码匹配位数,之前的项目都工作的好好的,但到了KK时,在sqlite库中引用property的相关方法,却一直编译error... 折腾了好久,发现从 ...

  9. circRNA 在人和小鼠脑组织中的表达

    circRNA 是一类动物体内的内源性的RNA,尽管circRNA的种类丰富,但是其在神经系统中的 功能,并不清楚.科学家通过对人和小鼠的不同脑部组织的RNA 测序,发现了上千种circRNA,经过分 ...

  10. Mac: Alias[设置命令的别名]

    设置`.bash_profile` 1.打开终端`Terminal` 2.输入命令`cd ~`到用户主目录 $ cd ~ 3.生成一个新文件 $ touch .bash_profile 4.使用喜欢的 ...