今年暑假不AC(水题)
来源:互联网 发布:一骑当千镜头数据 编辑:程序博客网 时间:2024/05/02 01:39
虽然这道题水的不行,但是虽然做了不少题,但是贪心一直是自己的一个BUG,今天稍微做了点,作为理解贪心的一个开始...
贪心的特点性质见博客http://blog.csdn.net/u014665013/article/details/40748115
打开题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2037
#include <iostream>#include <string>#include<algorithm>using namespace std;struct T{int start,end;}arr[110];bool compare(T a,T b){return a.end<b.end; //升序排列,如果改为return a>b,则为降序}int main (){int n;while(scanf("%d",&n)&&n!=0){int i=0;int temp=n;while(n--){scanf("%d%d",&arr[i].start,&arr[i].end);i++;}sort(arr,arr+temp,compare);int count=1,mem=arr[0].end;for(int j=1;j<temp;j++)if(arr[j].start>=mem){count++,mem=arr[j].end;}printf("%d\n",count);}return 0;}
0 0
- 今年暑假不AC(水题)
- 今年暑假不AC?
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- 今年暑假不AC
- IOS-usr/include-objc-NSObject-消息机制工作原理
- c语言自学笔记
- TCP/IP详解卷2:实现 第二章mbuf:存储器缓存 笔记一
- 1的个数
- struts2中常量配置
- 今年暑假不AC(水题)
- linux cat命令详解
- DFS+uva10317
- Android 布局
- <climits>头文件定义的符号常量
- Android SDK Manager 在线更新时出现Time Out 解决方法
- Struts2 MySQL数据库访问
- GPU架构解析——NVIDIA\AMD
- VNC介绍(第二篇)