HDOJ 1257 最少拦截系统 贪心算法again! so easy...........................

check the problem here:http://acm.hdu.edu.cn/showproblem.php?pid=1257

the AC code:

#include<iostream>
#include<string>
#include <cstdio>
#include <cmath>
#include<vector>
#include<algorithm>
#include<sstream>
#include<cstdlib>
using namespace std;
struct node{
	int h;
	int flag;
};
int main()
{
	int n;
	vector<node> buf;
	node tmp;
	while(cin>>n)
	{
		if(n==0)continue;
		for(int i=0;i<n;i++)
		{
			cin>>tmp.h;
			tmp.flag=0;
			buf.push_back(tmp);
		}
		int t=0;
		for(vector<int>::size_type i=0;i!=buf.size();i++)
		{
			tmp=buf[i];
			if(tmp.flag==0){
				tmp.flag=1;
				for(vector<int>::size_type j=i+1;j!=buf.size();j++){
					if(buf[j].flag==0&&buf[j].h<=tmp.h){
						buf[j].flag=1;
						tmp=buf[j];
					}
				}
				t++;
			}
		}
		cout<<t<<endl;
		buf.clear();
	}
	return 0;
}


你可能感兴趣的:(Algorithm,数据结构,C++,算法,struct,greedy)