hdoj1051_Wooden Sticks(贪心)

来源:互联网 发布:mysql数据库购买 编辑:程序博客网 时间:2024/05/16 17:39
#include<iostream>#include<vector>#include<algorithm>#include<utility>using namespace std;bool cmpl(pair<int,int> p1,pair<int,int> p2){    if (p1.first != p2.first)        return p1.first < p2.first;    return p1.second < p2.second;}vector<pair<int, int>> v, tmp;int main(){    int t;    cin >> t;    for (int i = 0; i < t; i++)    {        int n;        cin >> n;        v.clear();        for (int j = 0; j < n; j++)        {            int tl, tw;            cin >> tl >> tw;            v.push_back(make_pair(tl, tw));        }        sort(v.begin(), v.end(), cmpl);        tmp.clear();        tmp.push_back(make_pair(v[0].first, v[0].second));        for (int j = 0; j < n; j++)        {            int k=0;            for (; k < tmp.size(); k++)            {                if (v[j].first >= tmp[k].first&&v[j].second >= tmp[k].second)                {                    tmp[k].first = v[j].first, tmp[k].second = v[j].second;                    break;                }            }            if (k == tmp.size())                tmp.push_back(make_pair(v[j].first, v[j].second));        }        cout << tmp.size() << endl;    }    return 0;}
0 0
原创粉丝点击