[USACO12MAR] 摩天大楼里的奶牛 Cows in a Skyscraper
题目描述
A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, they had a problem. Refusing to climb back down using the stairs, the cows are forced to use the elevator in order to get back to the ground floor.
The elevator has a maximum weight capacity of W (1 <= W <= 100,000,000) pounds and cow i weighs C_i (1 <= C_i <= W) pounds. Please help Bessie figure out how to get all the N (1 <= N <= 18) of the cows to the ground floor using the least number of elevator rides. The sum of the weights of the cows on each elevator ride must be no larger than W.
给出n个物品,体积为w[i],现把其分成若干组,要求每组总体积<=W,问最小分组。(n<=18)
题目解析
模拟退火
话说啊,贪心是错的,虽然一眼看上去是没有问题的。
贪心:75分
裸贪心显然是错的,证明略。
对这道题而言就是略微调整w的范围。
Code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<ctime>
using namespace std; const int MAXN = ; int n,w,ans,tim;
int a[MAXN],s[MAXN];
double T,e; bool cmp(int x,int y) {
return x > y;
} inline bool getposs() {
T *= e;
if(rand() % < T) return false;
else return true;
} inline void clean() {
T = , e = 0.9;
memset(s,,sizeof(s));
tim = ;
return;
} int main() {
srand(time(NULL));
scanf("%d%d",&n,&w);
w *= 1.005;
for(int i = ;i <= n;i++) {
scanf("%d",&a[i]);
}
sort(a+,a++n,cmp);
bool flag = false;
int cnt = ;
ans = 0x3f3f3f3f;
while(cnt--) {
clean();
for(int i = ;i <= n;i++) {
flag = false;
for(int j = ;j <= tim;j++) {
if(w - s[j] >= a[i] && getposs()) {
s[j] += a[i];
flag = true;
break;
}
}
if(!flag) s[++tim] += a[i];
}
ans = min(ans,tim);
}
printf("%d\n",ans);
return ;
}
[USACO12MAR] 摩天大楼里的奶牛 Cows in a Skyscraper的更多相关文章
- [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
洛谷题目链接:[USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 题目描述 A little known fact about Bessie and friends is ...
- 洛谷P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 题目描述 A little known fact about Bessie and friends is ...
- P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
题目描述 给出n个物品,体积为w[i],现把其分成若干组,要求每组总体积<=W,问最小分组.(n<=18) 输入格式: Line 1: N and W separated by a spa ...
- 洛谷 P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better k ...
- P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 状压dp
这个状压dp其实很明显,n < 18写在前面了当然是状压.状态其实也很好想,但是有点问题,就是如何判断空间是否够大. 再单开一个g数组,存剩余空间就行了. 题干: 题目描述 A little k ...
- LUOGU P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better k ...
- [bzoj2621] [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
题目链接 状压\(dp\) 根据套路,先设\(f[sta]\)为状态为\(sta\)时所用的最小分组数. 可以发现,这个状态不好转移,无法判断是否可以装下新的一个物品.于是再设一个状态\(g[sta] ...
- [luoguP3052] [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper(DP)
传送门 输出被阉割了. 只输出最少分的组数即可. f 数组为结构体 f[S].cnt 表示集合 S 最少的分组数 f[S].v 表示集合 S 最少分组数下当前组所用的最少容量 f[S] = min(f ...
- [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper (状态压缩DP)
不打算把题目放着,给个空间传送门,读者们自己去看,传送门(点我) . 这题是自己做的第一道状态压缩的动态规划. 思路: 在这题中,我们设f[i]为i在二进制下表示的那些牛所用的最小电梯数. 设g ...
随机推荐
- python3 + selenum 环境搭建
一.安装python3 打开python3官网https://www.python.org/,选择下载相应平台版本. 下载完成之后,根绝需要安装.注意:在安装时需勾选左下角“add python to ...
- HDU1244:Max Sum Plus Plus Plus
题目链接:Max Sum Plus Plus Plus 题意:在n个数中取m段数使得这m段数之和最大,段与段之间不能重叠 分析:见代码 //dp[i][j]表示前i个数取了j段的最大值 //状态转移: ...
- 洛谷P3287 [SCOI2014]方伯伯的玉米田(树状数组)
传送门 首先要发现,每一次选择拔高的区间都必须包含最右边的端点 为什么呢?因为如果拔高了一段区间,那么这段区间对于它的左边是更优的,对它的右边会更劣,所以我们每一次选的区间都得包含最右边的端点 我们枚 ...
- CentOS中设置Windows共享文件夹
在CentOS中设置Samba可实现和Windows共享文件夹.常见的需求:1)用户能够在Windows机器上通过共享文件夹访问远程Linux服务器上自己的主目录:2)用户能够在Windows机器上访 ...
- VS2013程序打包报 ISEXP : error -****: An error occurred streaming
原因缺少打包文件 解决方案: 找到打包文件 右击选择 downLoad selected item
- 【同步工具类】CountDownLatch
闭锁是一种同步工具类,可以延迟线程的进度直到其达到终止状态. 作用:相当于一扇门,在到达结束状态之前,这扇门一直是关闭的,并且没有任务线程能够通过,当到达结束状态时,这扇门会打开并允许所有的线程通过, ...
- typedef struct和struct 的区别 用途
刚刚想到的,我们在用结构体的时候会遇到'->'和'.',这是什么情况呢? 不能混用的(c和c++不同语言对它们没有影响) 我说的不能混用的意思是'.'用于结构体指针的指向......而'-& ...
- javascript:void(0)与#区别
javascript:void(0) 鼠标点击时,不会跳转到其他页面,且停留在原地 # 鼠标点击时,不会跳转到其他页面,但会回到顶部
- spring tool suite开发环境搭建
先把是构建工具maven: maven里面有一个conf文件夹,然后里面有个setting.xml配置文件,先要把项目要的setting.xml覆盖这个原来的配置文件. 这个maven配置文件有一个作 ...
- php微信自动发红包
<?phpheader('Content-type:text');define("TOKEN", "weixin");$wechatObj = new w ...