生日蛋糕 POJ - 1190 搜索 数学
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 搜索 数学的更多相关文章
- 生日蛋糕 POJ - 1190 (搜索+剪枝)
7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱.当 ...
- 洛谷 P1731 [NOI1999]生日蛋糕 && POJ 1190 生日蛋糕
题目传送门(洛谷) OR 题目传送门(POJ) 解题思路: 一道搜索题,暴力思路比较容易想出来,但是这道题不剪枝肯定会TLE.所以这道题难点在于如何剪枝. 1.如果当前状态答案已经比我们以前某个状态 ...
- 生日蛋糕 POJ - 1190
7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱.当 ...
- poj 1190 DFS 不等式放缩进行剪枝
F - (例题)不等式放缩 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submi ...
- catch that cow POJ 3278 搜索
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...
- POJ 1190 生日蛋糕 【DFS + 极限剪枝】
题目传送门:http://poj.org/problem?id=1190 参考剪枝:https://blog.csdn.net/nvfumayx/article/details/6653111 生日蛋 ...
- POJ 1190 生日蛋糕题解
题目地址:http://poj.org/problem?id=1190 一道很有趣的搜索题--主要是剪枝-- 我弄了5个剪枝: 1.当前剩余层数>=上层半径,剪掉 2.当前剩余层数>=上层 ...
- Codevs 1710 == POJ 1190 生日蛋糕 == 洛谷P1731
生日蛋糕 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ ...
- 【POJ - 1190】生日蛋糕 (dfs+剪枝)
Descriptions: 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为 ...
随机推荐
- java框架篇---hibernate(一对一)映射关系
对象-关系映射(Object/Relation Mapping,简称ORM),是随着面向对象的软件开发方法发展而产生的,是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术,本质上就是将数据从 ...
- c++ 出现“ error LNK2019: 无法解析的外部符号 该符号在函数 中被引用"错误原因
一般问题出在 (1)XXX.lib头文件,这个要包含(不然编译也不能通过) (2)需要XXX.lib或XXX.dll库.手动添加,项目->属性->配置属性->链接器->输入 然 ...
- Java知多少(98)Graphics类的绘图方法
Graphics类提供基本绘图方法,Graphics2D类提供更强大的绘图能力.本节讲解Graphics类,下节讲解Graphics2D. Graphics类提供基本的几何图形绘制方法,主要有:画线段 ...
- HttpWebRequest - Asynchronous Programming Model/Task.Factory.FromAsyc
Posted by Shiv Kumar on 23rd February, 2011 The Asynchronous Programming Model (or APM) has been aro ...
- ubuntu GCC 版本切换
(1) 查看gcc以及g++的版本 gcc -v g++ -v star@ai:~ $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_L ...
- mysql wait_timeout 8小时问题解决,tomcat数据源的配置
异常报错: 2017-02-13 09:30:17.597 [startQuertz_Worker-6] ERROR com.autoyol.task.TransStatManageTask#exec ...
- easyui tree 默认选中第一个元素
系统采用ajax异步调用后端接口做数据呈现,有个场景就是加载的树形菜单默认选中第一行,网上有人分享的解决方案能实现效果(http://aokunsang.iteye.com/blog/1489204) ...
- tomcat 下安装 MantisBT
环境 OS:win8.1 up1 64bit tomcat :9.0.0 64bit php: php-7.1.7-nts-Win32-VC14-x64.zip postgres: postgresq ...
- SQL Server -- 随笔
-- 判断是否存在 LimeNextMonthBirthday 表 ) PRINT '存在' ELSE PRINT'不存在' -- 如果存在 则删除 没有 则打印 不存在 ) DROP TABLE L ...
- Android开发训练之第五章第七节——Transmitting Network Data Using Volley
Transmitting Network Data Using Volley GET STARTED DEPENDENCIES AND PREREQUISITES Android 1.6 (API L ...