uva_1422 Processor

题目链接

题意:

  有n个任务, 每个任务要在规定的时间[l, r]内完成, 工作量为 w, 每个任务可以分开完成。

  求, 使得所有任务都完成的最大速度的最小值。

思路:

  最大值最小问题, 二分。

  因为是要完成所有任务, 所以先按开始时间排序, 接下来二分速度。

  因为任意两个任务之间的关系只有两种, 1)相交或者包含 2)相切或者相离

  如果是情况 2) 那么不需要特殊处理, 按顺序处理过去即可。

  如果是情况 1) 那么需要将这个时间段内的任务按照结束时间来进行处理, 结束时间小的优先完成。

  然后枚举时间, 从1 开始处理过去, 看是否能处理完所有任务即可。

代码:

  

  1 #include <cmath>
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <cstdlib>
  5 #include <ctime>
  6 #include <set>
  7 #include <map>
  8 #include <list>
  9 #include <stack>
 10 #include <queue>
 11 #include <string>
 12 #include <vector>
 13 #include <fstream>
 14 #include <iterator>
 15 #include <iostream>
 16 #include <algorithm>
 17 using namespace std;
 18 #define LL long long
 19 #define INF 0x3f3f3f3f
 20 #define MOD 1000000007
 21 #define eps 1e-6
 22 #define MAXN 10010
 23 #define MAXM 100
 24 #define dd {cout<<"debug"<<endl;}
 25 #define pa {system("pause");}
 26 #define p(x) {printf("%d\n", x);}
 27 #define pd(x) {printf("%.7lf\n", x);}
 28 #define k(x) {printf("Case %d: ", ++x);}
 29 #define s(x) {scanf("%d", &x);}
 30 #define sd(x) {scanf("%lf", &x);}
 31 #define mes(x, d) {memset(x, d, sizeof(x));}
 32 #define do(i, x) for(i = 0; i < x; i ++)
 33 #define dod(i, x, l) for(i = x; i >= l; i --)
 34 #define doe(i, x) for(i = 1; i <= x; i ++)
 35 struct node
 36 {
 37     int l;
 38     int r;
 39     int t;
 40     int no;
 41     bool operator < (const struct node &y) const
 42     {
 43         return r > y.r;
 44     }
 45 };
 46 int n, sum;
 47 struct node f[MAXN];
 48 int w[MAXN];
 49 bool cmp(const struct node &x, const struct node &y)
 50 {
 51     return x.l == y.l? x.r < y.r : x.l < y.l;
 52 }
 53 void read()
 54 {
 55     sum = 0;
 56     scanf("%d", &n);
 57     for(int i = 0; i < n; i ++)
 58     {
 59         scanf("%d %d %d", &f[i].l, &f[i].r, &f[i].t);
 60         sum += f[i].t;
 61         f[i].no = i;
 62     }
 63     sort(f, f + n, cmp);
 64 }
 65 bool is_ok(int x)
 66 {
 67     priority_queue <struct node> Q;
 68     for(int i = 0; i < n; i ++)
 69         w[f[i].no] = f[i].t;
 70     int i = 0;
 71     int pos = 1;
 72     while(true)
 73     {
 74         while(i < n && f[i].l <= pos) Q.push(f[i ++]);
 75
 76         int ts = x;
 77         while(!Q.empty() && ts)
 78         {
 79             struct node temp = Q.top();
 80
 81             if(temp.r <= pos) return false;
 82
 83             w[temp.no] -= ts;
 84             if(w[temp.no] > 0)
 85                 ts = 0;
 86             else if(w[temp.no] <= 0)
 87             {
 88                 ts = -w[temp.no];
 89                 Q.pop();
 90             }
 91         }
 92
 93         if(i == n && Q.empty()) return true;
 94         pos ++;
 95     }
 96     return false;
 97 }
 98 int get_ans()
 99 {
100     int l = 1, r = sum;
101     while(l <= r)
102     {
103         int mid = (l + r) / 2;
104         if(is_ok(mid))
105             r = mid - 1;
106         else
107             l = mid + 1;
108     }
109     return l;
110 }
111
112 int main()
113 {
114     int T;
115     scanf("%d", &T);
116     while(T --)
117     {
118         read();
119         printf("%d\n", get_ans());
120     }
121     return 0;
122 }

时间: 2024-11-01 02:39:29

uva_1422 Processor的相关文章

Processor Speculative &amp; pipeline

Branch-Prediction in a Speculative Dataflow Processor http://cseweb.ucsd.edu/~tullsen/mteac5/kuszmaul.pdf

8.Processor

1.概述 Sink Group允许用户将多个Sink组合成一个实体. Flume Sink Processor 可以通过切换组内Sink用来实现负载均衡的效果,或在一个Sink故障时切换到另一个Sink. sinks – 用空格分隔的Sink集合 processor.type default 类型名称,必须是 default.failover 或 load_balance 2.Default Sink Processor Default Sink Processor 只接受一个 Sink. 不要

Jafka来源分析——Processor

Jafka Acceptor接受client而建立后的连接请求,Acceptor会将Socket连接交给Processor进行处理.Processor通过下面的处理步骤进行client请求的处理: 1. 读取client请求. 2. 依据client请求类型的不同,调用对应的处理函数进行处理. Processor读取client请求是一个比較有意思的事情,须要考虑两个方面的事情:第一,请求规则(Processor须要依照一定的规则进行请求的解析).第二,怎样确定一次请求的读取已经结束(由于是非堵

Inter-partition communication in multi-core processor

A multi-core processor includes logical partitions that have respective processor cores, memory areas, and Ethernet controllers. At least one of the Ethernet controllers is disabled for external communication and is assigned as an inter-partition Eth

Flexible implementation of a system management mode (SMM) in a processor

A?system?management?mode?(SMM) of operating a processor includes only a basic set of hardwired hooks or mechanisms in the processor for supporting SMM. Most of SMM functionality, such as the processing actions performed when entering and exiting SMM,

Method and apparatus for transitioning between instruction sets in a processor

A data processor (104) is described. The data processor (104) is capable of decoding and executing a first instruction (212) of a first instruction set and a second instruction (213-219) in a second instruction set wherein the first instruction (212)

HP Microserver Gen8 Processor FAQ

http://homeservershow.com/forums/index.php?/topic/6596-hp-microserver-gen8-processor-faq/ This guide is a work in progress.  After reading some other people's questions about processors for the Microserver Gen8, including "What's the best choice for

Maintaining processor resources during architectural events

In one embodiment of the present invention, a method includes switching between a first address space and a second address space, determining if the second address space exists in a list of address spaces; and maintaining entries of the first address

PatentTips - Zero voltage processor sleep state

BACKGROUND Embodiments of the invention relate to the field of electronic systems and power management. More particularly, embodiments of the invention relate to a method and apparatus for a zero voltage processor sleep state. As the trend toward adv