HDOJ 1050 moving tables 之线段树解法
来源:互联网 发布:flash网站源码下载 编辑:程序博客网 时间:2024/05/16 01:45
Problem 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.
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.
Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
Output
The output should contain the minimum time in minutes to complete the moving, one per line.
Sample Input
3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
Sample Output
102030//// main.cpp// 线段树//// Created by 张嘉韬 on 16/3/17.// Copyright © 2016年 张嘉韬. All rights reserved.//#include <iostream>#include <cstring>using namespace std;int max(int a,int b){ if(a>b) return a; else return b;}struct Node{ int num; int f; int L; int l; int r; Node *leftson; Node *rightson;};Node *creat(int s,int e){ Node *root =new Node; root->f=root->num=0; root->l=s; root->r=e; root->L=s-e; root->rightson=root->leftson=NULL; if(root->L>=2) { root->leftson=creat(s,(s+e)/2); root->rightson=creat((s+e)/2,e); } return root;}void insert(int c,int d,Node *root){ cout<<root->l<<endl; if(c<=root->l&&d>=root->r) {root->num++;cout<<root->num;} else { if(c<(root->l+root->r)/2) insert(c,d,root->leftson); if(d<(root->r+root->l)/2) insert(c,d,root->rightson); }}int maxnum(Node *root){ if(root->L==1) return root->num; else { return root->num+max(maxnum(root->leftson),maxnum(root->rightson)); }}int main(int argc, const char * argv[]) { freopen("/Users/zhangjiatao/Desktop/input.txt","r",stdin); int T; cin>>T; for(int k=1;k<=T;k++) { Node *root; root=creat(1,400); cout<<root<<endl; int n,a[300][2];//0 is s ,1 is e; cin>>n; for(int i=1;i<=n;i++) cin>>a[i][0]>>a[i][1]; for(int i=1;i<=n;i++) { if(a[i][0]>a[i][1]) { int temp; temp=a[i][0]; a[i][0]=a[i][1]; a[i][1]=temp; } if(a[i][0]%2==0) a[i][0]=a[i][0]-1; if(a[i][1]%2==1) a[i][1]=a[i][1]+1; insert(a[i][0],a[i][1],root); } cout<<10*maxnum(root); } return 0;}
0 0
- HDOJ 1050 moving tables 之线段树解法
- hdoj 1050 Moving Tables
- hdoj 1050 Moving Tables
- HDOJ 1050 Moving Tables
- HDOJ 1050 Moving Tables
- HDOJ 1050 Moving Tables
- HDOJ 1050 Moving Tables
- HDOJ 1050 Moving Tables
- HDOJ--1050Moving Tables!!
- hdoj.1050 Moving Tables 20140811
- HDOJ 1050 Moving Tables 【贪心】
- HDOJ 1050 Moving Tables (贪心)
- HDOJ HDU 1050 Moving Tables
- HDOJ Moving Tables JAVA 1050
- HDOJ 1050 Moving Tables解题报告
- HDOJ 1050:Moving Tables 解题报告
- HDOJ 1050 Moving Tables 贪心so easy!!
- HDOJ 1050 Moving Tables(贪心)
- maven tomcat插件热部署配置过程
- sqlite 学习(一)
- 3、ExtJs写的js页面中的输入框的值如何传输到Java后台Controller控制层?
- Object-C @property 小结
- 自定义app打开协议
- HDOJ 1050 moving tables 之线段树解法
- 蓝桥杯之年月日得到周几(年月日问题,包含平瑞年算法)
- 模板的声明和实现为何要放在头文件中?
- 对jquery.validate 的一些感悟
- android中用style简化布局文件
- Java集合框架:Arrays工具类
- android错误总结
- Tomcat迁移到weblogic的几个问题
- android中延时操作三种方式