• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Lt.Royce"Phantom"
博客园    首页    新随笔    联系   管理    订阅  订阅
2013年3月22日
区间覆盖问题的贪心策略
摘要: 区间覆盖问题数轴上有n个闭区间[ai,bi],选择尽量少的区间覆盖一条指定线段[s,t]。《算法竞赛入门经典》P154 重点说一下区间覆盖的贪心策略 首先将所有区间超出[s,t]的部分切掉,再对所有区间按a从大到小排序①,如果区间1的起点大于s,则无解。对n个区间扫描一次,代码:l = area[0].a;r = area[0].b; //把第一个区间的左右端点付给左右边界lr。②cnt = 1; //计数已记录下第一个区间for(i = 1;i < n;i++){ //从第二个区间开始扫描 if(area[i].a > r) break; //不能和当前区间链接,无解 else 阅读全文
posted @ 2013-03-22 17:52 Lt.Royce"Phantom" 阅读(440) 评论(0) 推荐(0)
UVa 10382 Watering Grass
摘要: #include<cstdio>#include<cmath>#include<algorithm>using namespace std;const int MAXN = 10001;struct node{ double s,t; bool operator < (const node& x) const { if(s!=x.s) return s <x.s; else return t >x.t; }};int main(){ int n,cnt; double w,l,p,r; struct node num[MAXN]; 阅读全文
posted @ 2013-03-22 16:20 Lt.Royce"Phantom" 阅读(146) 评论(0) 推荐(0)
2013年3月21日
UVa 10340 All in All
摘要: 数组需要开的很大#include<cstdio>#include<cstring>using namespace std;const int MAXN = 1000000;int main(){ char s1[MAXN],s2[MAXN]; while(scanf("%s%s",s1,s2)==2) { int i=0; for(int j=0;s1[i] && s2[j];j++) if(s1[i]==s2[j]) i++; if(s1[i]==0) printf("Yes\n"); else printf(& 阅读全文
posted @ 2013-03-21 12:38 Lt.Royce"Phantom" 阅读(88) 评论(0) 推荐(0)
UVa 10970 Big Chocolate
摘要: 找规律 include<cstdio>using namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m)==2) printf("%d\n",n*m-1); return 0;} 阅读全文
posted @ 2013-03-21 12:16 Lt.Royce"Phantom" 阅读(82) 评论(0) 推荐(0)
UVa 1368 DNA Consensus String
摘要: 题目比较难懂,求一个串使它到所有Si的距离和最小 #include<cstdio>#include<cstring>using namespace std;const int MAXN = 50;const int MAXM = 1001;int n,m,cnt[MAXM][27];int ham(char *s1,char *s2){ int c=0; for(int i=0;i<m;i++) if(s1[i]!=s2[i]) c++; return c;}int main(){ int T; char s[MAXM]; scanf("%d" 阅读全文
posted @ 2013-03-21 11:13 Lt.Royce"Phantom" 阅读(133) 评论(0) 推荐(0)
2013年3月20日
UVa 1339 Ancient Cipher
摘要: #include<cstdio>#include<algorithm>using namespace std;const int MAXN = 500000;struct node{ int i; bool is; bool operator < (const node& x)const { return i>x.i; }};int main(){ int T; int n; struct node a[MAXN]; scanf("%d",&T); while(T--) { scanf("%d",&am 阅读全文
posted @ 2013-03-20 19:17 Lt.Royce"Phantom" 阅读(122) 评论(0) 推荐(0)
UVa 11039 Building designing
摘要: #include<cstdio>#include<algorithm>using namespace std;const int MAXN = 500000;struct node{ int i; bool is; bool operator < (const node& x)const { return i>x.i; }};int main(){ int T; int n; struct node a[MAXN]; scanf("%d",&T); while(T--) { scanf("%d",&am 阅读全文
posted @ 2013-03-20 17:52 Lt.Royce"Phantom" 阅读(114) 评论(0) 推荐(0)
UVa 11636 Hello World!
摘要: #include<cstdio>#include<cmath>using namespace std;int main(){ int n,T=1; while(scanf("%d",&n),n>0) { printf("Case %d: %d\n",T++,(int)ceil(log10(n)/log10(2))); //换底公式 } return 0;} 阅读全文
posted @ 2013-03-20 15:43 Lt.Royce"Phantom" 阅读(79) 评论(0) 推荐(0)
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3