[luogu]P1248 加工生产调度
题目传送门
分析
考虑一种贪心排序,还是用 临项交换 的方法
假设产品 和 相邻,表示所需时间
不交换时,耗时
交换时,耗时
若满足不交换更优,则,即
按照此排序,同时考虑到上述柿子左边和右边相等时,特殊判断
可以参考上一篇皇后游戏
相等时优先把更短的放在后面,加快结束
代码
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rg register
inline int read(){
rg int x = 0, f = 1;
rg char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return x * f;
}
const int N = 1e3 + 1;
int n;
struct production{
int a, b, d, id;
bool operator <(productioin x) const{
if (min(a, x.b) == min(b, x.a))
return b > x.b;
return min(a, x.b) < min(b, x.a);
}
/*bool operator < (production e) const{
if (d != e.d) return d < e.d;
else if (d > 0) return b > e.b;
else return a < e.a;
}*/
}t[N];
inline void init(){
n = read();
for (int i(1); i <= n; ++i) t[i].a = read();
for (int i(1); i <= n; ++i) t[i].b = read(), t[i].id = i;
}
inline void doit(){
/*for (int i(1); i <= n; ++i)
if (t[i].a == t[i].b) t[i].d = 0;
else t[i].d = t[i].a > t[i].b ? 1 : -1;*/
sort(t + 1, t + 1 + n);
int t1 = 0, t2 = 0;
for (int i(1); i <= n; ++i){
t1 += t[i].a;
t2 = max(t2, t1) + t[i].b;
}
printf("%d\n", t2);
for (int i(1); i <= n; ++i)
printf("%d ", t[i].id);
}
int main(){
ios::sync_with_stdio(false);
cout.tie(NULL);
init();
doit();
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)