HDU 1050 Moving Tables (贪心 区间最大叠加数)
2013-01-22 11:02
603 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050
参考链接:http://blog.csdn.net/code_pang/article/details/8251240
思路1:贪心
思路2:区间最大叠加数
参考链接:http://blog.csdn.net/code_pang/article/details/8251240
思路1:贪心
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) struct Point { int s,e; bool vis; void get () { scanf("%d%d",&s,&e); int small=(min(s,e)+1)/2; //此处注意 int big=(max(s,e)+1)/2; s=small; e=big; vis=false; } bool operator < (const Point& _P) const //第一关键字:开始时间 { return s<_P.s||(s==_P.s&&e<_P.e); }; }data[205],temp; int n; int Find (int start) //寻找从data[start]开始的第一个没有访问过的点 { for (int i=start;i<n;i++) if (data[i].vis==false) return i; return n; } int main () { int T; scanf("%d",&T); while (T--) { int i,num=0,ans=0; scanf("%d",&n); for (i=0;i<n;i++) data[i].get(); sort(data,data+n); while (num<n) { int first=Find(0); temp=data[first]; data[first].vis=true; num++; for (i=Find(first);i<n;i++) if (data[i].s>temp.e && data[i].vis==false) { num++; temp=data[i]; data[i].vis=true; } ans++; } printf("%d\n",ans*10); } return 0; } /* 1 4 10 5 1 4 8 9 3 6 Out 20 */
思路2:区间最大叠加数
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) int main () { int T,n,cnt[205]; scanf("%d",&T); while (T--) { int i,s,e; memset(cnt,0,sizeof(cnt)); scanf("%d",&n); for (i=0;i<n;i++) { scanf("%d%d",&s,&e); int small=(min(s,e)+1)/2; //此处注意 int big=(max(s,e)+1)/2; s=small; e=big; for (int j=s;j<=e;j++) cnt[j]++; } int ans=-1; for (i=0;i<205;i++) if (ans<cnt[i]) ans=cnt[i]; printf("%d\n",ans*10); } return 0; }
相关文章推荐
- hdoj1050 moving tables 贪心 最大重叠区间数
- hdu 1050 Moving Tables(贪心)
- hdu 1050 Moving Tables(贪心算法---区间覆盖,重叠数)
- POJ 1083 && HDU 1050 Moving Tables (贪心)
- hdu 1050 Moving Tables(贪心)
- hdu 1050 Moving Tables(贪心)
- hdu 1050 Moving Tables (贪心)
- HDU 1050:Moving Tables【贪心 & 灵活】
- hdu 1050 Moving Tables(贪心)
- POJ 1083 && HDU 1050 Moving Tables(贪心)
- HDU-1050-Moving Tables(C++ && 贪心初步)
- HDU-1050 Moving Tables (贪心)
- hdu 1050 Moving Tables(贪心)
- hdu 1050 Moving Tables(迷之贪心...)
- acm hdu1050 Moving Tables(区间最大叠加数)
- hdu 1050 Moving Tables(贪心)
- HDU 1050 Moving Tables 【区间覆盖】
- POJ 1083 && HDU 1050 Moving Tables (贪心)
- hdu 1050 Moving Tables_贪心
- HDU 1050 Moving Tables 贪心!!