HDU - 1257

Subject
a country to defend against enemy missile attacks, to develop a missile interception system, but such a missile interceptor system has a flaw: Although it's the first rounds to reach any height, but each shell and should not exceed ago out of heights. One day, the enemy radar missile struck. As the system is still in beta, so only a system, and therefore may not intercept all the missiles.
how to do it? multi engage in several systems chant ! you talk about Daoman easy, cost it cost is a big problem ah so Anjiu here to help, please help calculate how many sets of interception system requires a minimum?..
the input
enter several sets of data each set of data including: total missile the number (a positive integer), so the missile flying height (the height of the radar data given is a positive integer of not greater than 30,000, separated by spaces)
the output
corresponding to each data output intercept all missiles minimum number of sets to be equipped with such missiles interceptor system.
the Sample the Input
8 389 207 155 300 299 170 158 65
the Sample the Output
2
-solving ideas
(interceptors fired artillery, enemy missile attacks)
for the smallest k sets interception system, Shells interceptor missile launch its highly monotonous descending.
For the first x and y-shells shells, there is always the x-height pieces of artillery interceptor missiles are less than the height of the y-intercept missiles did not shell height or the y-intercept missile shells were less than the height of the shells did x interceptor missile.
Suppose the height of the interceptor missile shell abstracted into a straight line slope of less than zero.
Blue for the x, y red to
assume that the above conditions are not satisfied Here Insert Picture Description
Here Insert Picture Description
so they can be turned into so
Here Insert Picture Description
Here Insert Picture Description
therefore assumption does not hold
So for the smallest k shells, for any two x, y, there is always the x-height pieces of artillery interceptor missiles are less than the height of the y-intercept missiles or artillery shells no y-intercept missile shells were less than the height of the shells did x interceptor missiles height.
Thus
practice a: find the smallest k shells can be converted to seek maximum length decrease subsequence problem.
Practice two: for any i-th missiles, it should be the minimum height (STL multiset can be easily solved by) the former i-1 missiles height higher than the missile and the missile altitude minus the
code the second approach

#include <cstdio>
#include <set>
#include <iostream> 
using namespace std;
multiset <int> s;
int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		int ans=0;
		s.clear();
		for (int i=1;i<=n;i++)
		  {
		  	int x;
		  	scanf("%d",&x);
		    if (s.upper_bound(x)!=s.end()) s.erase(s.upper_bound(x));
		  	else ans++;
		  	s.insert(x);
		  }
		printf("%d\n",ans);
	}
}
Published 14 original articles · won praise 0 · Views 154

Guess you like

Origin blog.csdn.net/weixin_45723759/article/details/103980162