【算法】Processing Management
来源:互联网 发布:淘宝联盟挣钱吗? 编辑:程序博客网 时间:2024/05/17 09:16
问题描述:
Assistant Manager Lee is on a visit to a factory run by a partner company.
A machine is cutting steel plates that are different in length and width.
However, a closer look found that the machine keeps operating only when the length and width of the steel plate it is cutting are equal or larger than those of the previous plate.
Otherwise, he found it takes one minute to prepare the machine working again.
After looking at the length and width of the steel plate ordered, time required for preparing the machine restarting if the order by which steel plate are cut is set could be reduced.
To help the partner company, he immediately starts writing a program that sets the order of cutting steel plates to minimize the time required for the restart of the machine. How did he write?
The steel plate cannot rotate and be mindful of the fact that when cutting a steel plate, it takes one minute to operate for the first time.
Time Limit : 2 sec (Java : 4 sec)
[Input]
There can be more than one test case in the input file. The first line has T, the number of test cases.
Then the totally T test cases are provided in the following lines (T <= 10 )
In each test case, the first line has an integer N(1 ≤ N ≤ 5,000), the number of steel plate ordered.
In the second line, information on each steel plate Li, Wi is given.
Li is the length of i-th steel plate, and Wi is the width of i-th steel plate. (1 ≤ Li, Wi ≤ 10,000)
[Output]
In the each line, output minimum time required for the machine to make all steel plates ordered.
[I/O Example]
Input
2
5
4 9 5 2 2 1 3 5 1 4
3
1 3 2 2 3 1
Output
2
3
分析:
源码:
#include <iostream>using namespace std;int N;int Li[5001];int Wi[5001];int Answer;struct lengthWidth{int l;int w;};struct lengthWidth input[5001];int compare(const void* a, const void* b){int l1 = ((struct lengthWidth *)a)->l;int l2 = ((struct lengthWidth *)b)->l;if (l1 == l2){return ((struct lengthWidth *)a)->w - ((struct lengthWidth *)b)->w;}else{return l1 - l2;}}int main(int argc, char** argv){int test_case;int T;/*The freopen function below opens input.txt file in read only mode, and afterward,the program will read from input.txt file instead of standard(keyboard) input.To test your program, you may save input data in input.txt file,and use freopen function to read from the file when using cin function.You may remove the comment symbols(//) in the below statement and use it.Use #include<cstdio> or #include<stdio.h> to use the function in your program.But before submission, you must remove the freopen function or rewrite comment symbols(//).*/// freopen("input.txt", "r", stdin);cin >> T;for (test_case = 0; test_case < T; test_case++){cin >> N;for (int i = 1; i <= N; i++){cin >> input[i].l >> input[i].w;}/*********************************** Implement your algorithm here. ************************************/qsort(&input[1], N, sizeof(struct lengthWidth), compare);Answer = 0;int j = 0;for (int i = 1; i <= N; i++){if (input[i].l == 0 && input[i].w == 0)continue;int cur_len = input[i].l;int cur_wid = input[i].w;for (j = i + 1; j <= N; j++){if (cur_len <= input[j].l && cur_wid <= input[j].w){cur_len = input[j].l;cur_wid = input[j].w;input[j].l = input[j].w = 0;}}input[i].l = input[i].w = 0;Answer++;}// Print the answer to standard output(screen).cout << Answer << endl;}return 0;//Your program should return 0 on normal termination.}
- 【算法】Processing Management
- 【算法】Fractional Multiscale Processing
- Period- End Processing in Oracle Order Management (Release 11i)
- Lifetime-Based Memory Management for Distributed Data Processing Systems
- 每天一道算法_5_Financial Management
- GLUT函数说明---事件处理(Event Processing)+窗口管理(Window Management)
- IBM LAS SYSTEM( 3 )——Spatial Management Client (administration)、Location、UI Processing
- GLUT事件处理(Event Processing)窗口管理(Window Management)函数
- GPS-Graph Processing System Graph Coloring算法分析 (三)
- 【image processing】动态时间规整(DTW)算法
- 【算法学习】【图像增强】【Retinex】Retinex Image Processing(NASA)
- C#+Arcengine实现GP工具中Data Management Tool》raster》raster processing中的clip功能(矢量数据对栅格数据的裁剪)
- Data-Intensive Text Processing with MapReduce第三章(1)-MapReduce算法设计-简介
- Data-Intensive Text Processing with MapReduce第三章(2)-MapReduce算法设计-3.1局部聚集
- Data-Intensive Text Processing with MapReduce第三章(5)-MapReduce算法设计-3.4 二次排序
- CCS算法(Contour-Constrained Superpixels for Image and Video Processing)
- Idle Processing
- Processing - 1
- PullToRefreshListView使用中的一些问题
- 屏幕截图
- spring揭秘 读书笔记 六 bean的一生
- html标签正则表达式
- Windows剪贴板操作简单小例
- 【算法】Processing Management
- hdoj 3488 Tour 【最小费用最大流】【KM算法】
- java.io.IOException: Server returned HTTP response code: 403 for URL: http://query.sse.com.cn/infodi
- STL学习----入门(1)[iterator]
- 一扫天下——ZXing使用全解析
- Spring 事务机制详解
- UE3 供游戏性程序员的使用的性能最优化方法
- hdu5402 Travelling Salesman Problem
- LinearPolar函数