zoukankan      html  css  js  c++  java
  • 加工生产调度

    题目描述

    思路

    代码

    #include <cstdio>
    
    int n, na, nb, ans;
    struct Node {
    	int a, b, c;
    } aa[1005], bb[1005], tmp;
    inline int read() {
    	int s = 0, f = 1;
    	char ch = getchar();
    	while (ch < '0' || ch > '9') {
    		if (ch == '-') f = -1;
    		ch = getchar();
    	}
    	while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    	return s * f;
    }
    void qsortA(int L, int R, Node * arr) {
    	int l = L, r = R;
    	int mid = arr[l + r >> 1].a;
    	while (l < r) {
    		while (arr[l].a < mid) l++;
    		while (arr[r].a > mid) r--;
    		if (l <= r) {
    			tmp = arr[l];
    			arr[l] = arr[r];
    			arr[r] = tmp;
    			l++, r--;
    		}
    	}
    	if (l < R) qsortA(l, R, arr);
    	if (L < r) qsortA(L, r, arr);
    }
    void qsortB(int L, int R, Node * arr) {
    	int l = L, r = R;
    	int mid = arr[l + r >> 1].b;
    	while (l < r) {
    		while (arr[l].b > mid) l++;
    		while (arr[r].b < mid) r--;
    		if (l <= r) {
    			tmp = arr[l];
    			arr[l] = arr[r];
    			arr[r] = tmp;
    			l++, r--;
    		}
    	}
    	if (l < R) qsortB(l, R, arr);
    	if (L < r) qsortB(L, r, arr);
    }
    int main() {
    	n = read();
    	for (int i = 1; i <= n; ++i) aa[i].a = read();
    	for (int i = 1; i <= n; ++i) aa[i].b = read();
    	for (int i = 1; i <= n; ++i) {
    		if (aa[i].a < aa[i].b) {
    			aa[++na] = aa[i], aa[na].c = i;
    		} else {
    			bb[++nb] = aa[i], bb[nb].c = i;
    		}
    	}
    	qsortA(1, na, aa); qsortB(1, nb, bb);
    	for (int j = 1; j <= nb; ++j) aa[++na] = bb[j];
    	for (int i = 1, a = 0, b = 0; i <= na; ++i) {
    		a += aa[i].a;
    		if (ans < a) {
    			ans = a + aa[i].b;
    		} else {
    			ans += aa[i].b;
    		}
    	}
    	printf("%d
    ", ans);
    	for (int i = 1; i <= na; ++i) {
    		printf("%d", aa[i].c);
    		if (i != na) putchar(' ');
    	}
    	return 0;
    }
    
  • 相关阅读:
    我深知黑暗,但心向光明(记毕业后第一次在北京求职)
    CF 1200E HASH模板
    CF580D
    CF1433F
    CF1451 E1交互题
    11.23-11.29 训练计划
    11.22 CF总结 #682
    sql问题:备份集中的数据库备份与现有的 '办公系统' 数据库不同
    内容导出成word
    让超链接无法跳转的方法
  • 原文地址:https://www.cnblogs.com/liuzz-20180701/p/11557790.html
Copyright © 2011-2022 走看看