您的位置:首页 > 其它

HDU ACM 11 2037 今年暑假不AC

2016-10-15 14:51 337 查看
贪吃算法

#include <iostream>
#include <algorithm>
using namespace std;
struct Lu
{
int x;
int y;
};Lu Hui[100];

int main()
{
int n;
while (cin >> n && n)
{
int j = 0;
int Yi = 1;
for (int i = 0; i < n; i++)
cin >> Hui[i].x >> Hui[i].y;
for (int i = 0; i < n; i++)
for (int x = i; x < n; x++)
if (Hui[i].y > Hui[x].y)
swap(Hui[i], Hui[x]);
for (int i = 1; i < n; i++)
if (Hui[i].x >= Hui[j].y)
{
Yi++;
j = i;
}
cout << Yi << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: