POJ1083 Moving Tables

来源:互联网 发布:深度linux硬盘怎么分区 编辑:程序博客网 时间:2024/05/16 12:19
题目要求时间最少,即尽可能让占用不同走廊的桌子并行运行。
设置一数组:dp[200],初始化为0。记录每个走廊占用的次数,所用时间极为最大占用次数*10

代码:

#include <iostream>#include <cstdlib>#include <string>#include <algorithm>using namespace std;struct node {    int start;    int end;};bool cmp(int a, int b) {    return a> b;}int main() {    int T;    int n;    int sum;    int tmp;    node a[450];    int dp[250];    cin>> T;    while(T--) {       cin >> n;       sum = 10;        for(int i = 0; i < n; i++){           cin>> a[i].start>> a[i].end;          if(a[i].start > a[i].end) {                      tmp = a[i].start;                      a[i].start = a[i].end;                      a[i].end = tmp;             }       }       memset(dp, 0, sizeof(dp));       for(int j = 0; j < n; j++){              for(int i = (a[j].start-1)/2;i <= (a[j].end-1)/2; i++) {                    dp[i]++;              }       }       sort(dp, dp+200, cmp);       cout << dp[0]*10<< endl;    }// system("pause");    return 0;}


原创粉丝点击