nyoj168 room arrangement line segment tree wiring check

room arrangement

Time Limit: 3000 ms | Memory Limit: 65535 KB
Difficulty: 2
describe

The 2010 Shanghai World Expo (Expo2010) is the 41st World Expo. It was held in Shanghai, China from May 1st to October 31st, 2010. This World Expo is also the first World Expo hosted by China. With the theme of "Better City, Better Life", the Shanghai World Expo will fully explore urban life in the 21st century.

The total investment of this World Expo reached 45 billion RMB, creating the largest scale record in the history of the World Expo. Attract 200 countries and international organizations to participate in the exhibition. 70 million visitors are expected.

In order to better receive visitors from all over the world during this period, the issue of how to reasonably arrange the accommodation of various hotels has been mentioned on the agenda. The Organizing Committee has received a large number of customer accommodation orders, and the content of each order includes the number of rooms to be accommodated, the starting time of accommodation and the number of days to be accommodated. In order to facilitate the management of the hotels in the whole city, the organizing committee hopes to arrange these orders with the purpose of meeting these orders with as few rooms as possible, so as to free up more rooms for arranging floating tourists.

The Organizing Committee requested DR.Kong to complete this task and make reasonable arrangements for these orders, so that the number of rooms that can meet the requirements of these orders is the least.

Assumption: Once the tourist on a certain order is arranged to a certain room, he will not change the room during the period of his reservation. In order to simplify the description, the starting time of accommodation on the order is the number of days from now. For example, if the order is (10, 30, 5), it means that the tourists request to use 10 rooms and stay for 5 consecutive days starting from the 30th day.

enter
The first line: T indicates that there are T
groups of data. The first line of each group of test data: N indicates the number of orders.
Next to each group of test data, there are N lines, each line has three integers.
=T<=100
1<=N<=10000 1<=A<=10 1<=B<=180 1<=c<=10
output
Outputs an integer that is the minimum number of rooms required to satisfy all orders.
sample input
1
3
3 10 4
4 9 3
3 12 6
Sample output
7
source

The 3rd Henan Province Programming Contest

Compared with 10,000 times of line insertion (interval update), the time consumption of checking 180 points is not so much, so use the line segment tree to check the points, and check the maximum value of 180 points.

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int c[200];

int lowbit(int x)
{
	return x&(-x);
}
 
void add(int i,int x)
{
	while(i<=180)
	{
		c[i]=c[i]+x;
		i=i+lowbit(i);
	}
 }

int sum(int i)
{
	int sum=0;
	while(i>0)
	{
		sum=sum+c[i];
		i=i-lowbit(i);
	}
	return sum;
}

intmain()
{
	//freopen("inA.txt","r",stdin);
	int t,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		int v,start,time;
		memset(c,0,sizeof(c));
		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d",&v,&start,&time);
			add(start,v);
			add(start+time,-v);	
		}
		int ans=0;
		for(int i=1;i<=180;i++)
		ans=max(ans,sum(i));
		printf("%d\n",ans);
	}
	
	return 0;
}

 
  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325732158&siteId=291194637