[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 ...
随机推荐
- 关于JAVA通过REST接口对arcGis Server数据进行增删改查
一: 添加要素 public void create(BoxVo boxVo) throws Exception { // 创建HTTP客户端 CloseableHttpClient httpclie ...
- asp.net mvc4 新特性
摘自:ASP.MVC Web编程 几种模板的解释
- CodeForces 723A The New Year: Meeting Friends (水题)
题意:给定 3 个数,求其中一个数到另外两个数之间的最短距离. 析:很明显选中间那个点了. 代码如下: #pragma comment(linker, "/STACK:1024000000, ...
- header的参数不能带下划线
移动端把一些公共参数放在了 header 了, 在 laravel 中使用 use \Illuminate\Http\Request; //这个是获取所有header信息Request::header ...
- 团队作业-项目Alpha版本发布
一. 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 这个作业要求在哪里 https://edu.cn ...
- C/C++带有空格的字符串输入
一.带有空格的字符串输入 (一)C++篇 1. 针对字符数组而言 方法一 getline() 读入整行数据,使用回车键输入换行符来确定输入结尾. 调用方法: cin.getline(str,len) ...
- Magento Order 状态详解
流程图:
- .net 字符串和JSON格式的互换
近期又做了个问卷调查,问卷调查一次性要保存一二十个题目和答案!所以嘞,博主为了偷懒,就直接把答卷内容保存成了Json格式! 好处当然是很多啦! 只需一个字段就能保存整个答卷的内容! 想想都刺激!哈哈~ ...
- 依赖注入(IOC) 详解
https://blog.csdn.net/qq_27093465/article/details/52547290 https://blog.csdn.net/qq_27093465/article ...
- 【CSS】3种CSS方法设置元素垂直水平居中
1. 宽高固定 设置要水平垂直居中的 div 的 position 为 absolute,left:50%; margin-left为负的这个元素宽度的一半,同理,top:50%;margin-top ...