POJ 1083 Moving Tables
来源:互联网 发布:彗星dns优化 编辑:程序博客网 时间:2024/05/17 06:59
Description
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.
The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.
For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.
【题目分析】
刚看到的时候一脸的蒙蔽(这哪里是动态规划的题目,就是贪心啊),被网上的列表深深的迷惑了,只需要统计每个教室经过的次数,然后选取最大值就可以了。
统计的时候用的是暴力,这样修改的复杂度是O(n)的,总体O(n^2)。如果改成前缀和的形式来修改和扫描就可以降低到O(1)的复杂度了,总体O(n)。
【代码】(好丑啊)
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int room[401];int main(){ int tt; cin>>tt; while (tt--) { memset(room,0,sizeof room); int n; cin>>n; for (int i=1;i<=n;++i) { int a,b; cin>>a>>b; if (a>b) swap(a,b); if (!(a&1)) a--; if (b&1) b++; for (int j=a;j<=b;++j) room[j]++; } int ans=0; for (int i=1;i<=400;++i) ans=max(ans,room[i]); cout<<ans*10<<endl; }}
- poj 1083 Moving Tables
- POJ 1083 Moving Tables
- poj 1083 Moving Tables
- POJ 1083 Moving Tables
- poj 1083-Moving Tables
- POJ 1083 Moving Tables
- POJ 1083 Moving Tables
- POJ 1083 Moving Tables
- poj 1083 Moving Tables
- POJ 1083 Moving Tables
- POJ 1083 Moving Tables
- poj 1083 Moving Tables
- poj 1083 Moving Tables
- POJ-1083-Moving Tables
- POJ 1083 Moving Tables
- poj 1083 Moving Tables
- POJ 1083 Moving Tables
- POJ 1083 Moving Tables
- LA 3704 Cellular Automaton【循环矩阵,快速幂】
- C ++ 虚函数 (转)
- poj3258River Hopscotch
- HDU 3366 Passage
- c++实现图像旋转任意角度
- POJ 1083 Moving Tables
- CodeIgniter框架源码笔记(9)——日志记录类Log.php
- 策略模式
- nyoj 17 单调递增最长子序列
- Android textview实现局部点击
- Js基础学习之-- 利用GET方法实现ajax请求
- POJ 2503 Babelfish(STL-map)
- 学习Android源码应该避免的
- 已知两种遍历序列求原始二叉树