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. Mac Apache WebDav 服务器配置

    1.WebDav 服务器 基于 http 协议的 "文件" 服务器. 实现文件的上传/下载/修改/删除. WebDav 权限 授权信息的格式 BASIC (用户名:口令)base6 ...

  2. 各类nosql db的功能与性能对比

    mongodb cassandra neo4j couchbase couchdb redis leveldb

  3. 【转载】Mysql load data infile用法(万级数据导入,在几秒之内)

    https://blog.csdn.net/u014082714/article/details/53173975 http://blog.itpub.net/26506993/viewspace-2 ...

  4. curl 调用jenkins的api

    jenkins提供了rest api,通过调用接口,可以执行一些job的操作,如构建job ,新建job,启用禁用等操作骑车 其次curl是什么? cURL是一个利用URL语法在命令行下工作的文件传输 ...

  5. ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

    命令: ansible -i hosts_20 st  -m shell -a 'service zabbix_agentd star'  -K --become ansible -i hosts_2 ...

  6. [svc]find+xargs/exec重命名文件后缀&文件操作工具小结

    30天内的文件打包 find ./test_log -type f -mtime -30|xargs tar -cvf test_log.tar.gz awk运算-解决企业统计pv/ip问题 find ...

  7. pandas DataFrame(3)-轴

    和numpy数组(5)-二维数组的轴一样,pandas DataFrame也有轴的概念,决定了方法是对行应用还是对列应用: 以下面这个数据为例说明: 这个数据是5个车站10天内的客流数据: rider ...

  8. linux每日命令(26):Linux文件属性详解

    Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模式.链接数量.所归属的用户和用户组.最近访问或修改的时间等内容.具体情况如下: 命令: ls -lih 输出: [root@loca ...

  9. Asp.Net MVC EF查询部分字段

    例如新闻表中有几十个字段,而我们只需要显示标题和时间2个字段 如果是再Controller中查询使用的话比较简单 public string ceshi() { dbEntities db = new ...

  10. Spring MVC学习摘要

    1. context:component-scan标签的use-default-filters属性的作用以及原理分析 http://www.cnblogs.com/hafiz/p/5875770.ht ...