HDU ACM 11 2037 今年暑假不AC

来源:互联网 发布:数据库的导入和导出 编辑:程序博客网 时间:2024/06/05 16:02

贪吃算法

#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;}


0 0
原创粉丝点击