BZOJ1150: [CTSC2007]数据备份Backup
2017-09-03 23:22
302 查看
1150: [CTSC2007]数据备份Backup
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2357 Solved: 957
[Submit][Status][Discuss]
Description
你在一家 IT 公司为大型写字楼或办公楼(offices)的计算机数据做备份。然而数据备份的工作是枯燥乏味的,因此你想设计一个系统让不同的办公楼彼此之间互相备份,而你则坐在家中尽享计算机游戏的乐趣。已知办公
楼都位于同一条街上。你决定给这些办公楼配对(两个一组)。每一对办公楼可以通过在这两个建筑物之间铺设网
络电缆使得它们可以互相备份。然而,网络电缆的费用很高。当地电信公司仅能为你提供 K 条网络电缆,这意味
着你仅能为 K 对办公楼(或总计2K个办公楼)安排备份。任一个办公楼都属于唯一的配对组(换句话说,这 2K
个办公楼一定是相异的)。此外,电信公司需按网络电缆的长度(公里数)收费。因而,你需要选择这 K 对办公
楼使得电缆的总长度尽可能短。换句话说,你需要选择这 K 对办公楼,使得每一对办公楼之间的距离之和(总距
离)尽可能小。下面给出一个示例,假定你有 5 个客户,其办公楼都在一条街上,如下图所示。这 5 个办公楼分
别位于距离大街起点 1km, 3km, 4km, 6km 和 12km 处。电信公司仅为你提供 K=2 条电缆。
/************************************************************** Problem: 1150 User: 33511595 Language: C++ Result: Accepted Time:672 ms Memory:95816 kb ****************************************************************/ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <queue> #include <vector> inline void read(int &x) { char ch = getchar(), c = ch;x = 0; while(ch < '0' || ch > '9')c = ch, ch = getchar(); while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar(); if(c == '-')x = -x; } const int INF = 0x3f3f3f3f; const int MAXN = 1000000 + 10; const int MAXM = 1000000 + 10; int n,m,cnt,b[MAXN << 2],ans,num,tmp; struct Node { int pre,nxt,value,num,cnt; Node(int _pre, int _nxt, int _value, int _num, int _cnt){pre = _pre, nxt = _nxt, value = _value, num = _num;cnt = _cnt;} Node(){} }node[MAXN << 2]; struct cmp { bool operator()(int a, int b) { return node[a].value > node[b].value; } }; std::priority_queue<int, std::vector<int>, cmp> q; int main() { read(n), read(m); read(tmp); for(register int i = 2;i <= n;++ i) { read(num); ++ cnt; node[cnt] = Node(cnt - 1,cnt + 1,num - tmp,1,cnt); tmp = num; q.push(cnt); } node[0] = Node(0,1,INF,0,0);++cnt; node[cnt] = Node(cnt - 1,0,INF,0,cnt); register int tmp,pre,nxt; int now = 0; while(q.size() && now < m) { tmp = q.top(), q.pop(); pre = node[tmp].pre, nxt = node[tmp].nxt; if(b[node[tmp].cnt])continue; if(now + node[tmp].num > m)continue; b[node[tmp].cnt] = b[node[pre].cnt] = b[node[nxt].cnt] = 1; ans += node[tmp].value; now += node[tmp].num; ++cnt; node[node[pre].pre].nxt = cnt; node[node[nxt].nxt].pre = cnt; node[cnt] = Node(node[pre].pre, node[nxt].nxt, node[pre].value + node[nxt].value - node[tmp].value, node[pre].num + node[nxt].num - node[tmp].num, cnt); q.push(cnt); } printf("%d", ans); return 0; }
BZOJ1150
相关文章推荐
- 【BZOJ】1150 [CTSC2007]数据备份Backup 堆+链表
- 【BZOJ 1150】 [CTSC2007]数据备份Backup
- bzoj1150 [CTSC2007]数据备份Backup
- bzoj 1150: [CTSC2007]数据备份Backup 贪心&堆
- bzoj 1150: [CTSC2007]数据备份Backup【链表+堆】
- BZOJ1150: [CTSC2007]数据备份Backup
- [贪心+堆] BZOJ1150: [CTSC2007]数据备份Backup
- bzoj 1150 CTSC: [CTSC2007]数据备份Backup
- bzoj 1150: [CTSC2007]数据备份Backup 贪心+优先队列
- BZOJ 1150: [CTSC2007]数据备份Backup 链表
- 【贪心+堆+链表】BZOJ1150(CTSC2007)[数据备份Backup]题解
- 【BZOJ 1150】[CTSC2007]数据备份Backup
- BZOJ1150(CTSC2007)[数据备份Backup]--贪心+链表+堆
- BZOJ 1150: [CTSC2007]数据备份Backup【贪心】
- BZOJ 1150 [CTSC2007] 数据备份Backup
- BZOJ 1150: [CTSC2007]数据备份Backup 贪心 链表 经典题
- bzoj 1150 [CTSC2007]数据备份Backup
- 【bzoj1150】[CTSC2007]数据备份Backup 模拟费用流+链表+堆
- 【链表】bzoj 1150: [CTSC2007]数据备份Backup
- bzoj1150 [CTSC2007]数据备份Backup