POJ 2528 Mayor's posters+zoj 1610 Count the Colors(数组记录)
来源:互联网 发布:艾克里里用什么软件 编辑:程序博客网 时间:2024/04/30 12:55
思路:
对于线段树区间覆盖的这种题。。我觉得我的办法也挺好,而且如果查询次数更多的话,我觉得线段树也不一定能过,这个办法只要n在10^5以下。。感觉10^5会死里。我觉得是可以过
目前至于到10^3 10^4
poj 2528
#include <iostream>#include <stdio.h>#include <cstring>using namespace std;int wall[10000001];int l[10005];int r[10005];int main(){ int T; cin>>T; while(T--) { memset(wall,0,sizeof(wall)); int n; scanf("%d",&n); int ans=0; for(int i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]); for(int k=n;k>=1;k--) { int yes=0; for(int i=l[k];i<=r[k];i++) { if(wall[i]!=0) { i=wall[i]; } else { wall[i]=r[k]; yes=1; } } if(yes) ans++; } cout<<ans<<endl; } return 0;}
zoj 1610
#include <stdio.h>#include <algorithm>#include <cstring>using namespace std;const int maxn=8005;int table[maxn];int color[maxn];int l[maxn];int r[maxn];int w[maxn];int ans[maxn];int main(){ int n; while(~scanf("%d",&n)) { memset(table,-1,sizeof(table)); memset(color,-1,sizeof(color)); memset(ans,0,sizeof(ans)); for(int i=1;i<=n;i++) { scanf("%d%d%d",&l[i],&r[i],&w[i]); l[i]++; } for(int i=n;i>=1;i--) { int cnt=0; for(int j=l[i];j<=r[i];) { if(table[j]==-1) { color[j] =w[i]; table[j]=r[i]; j++; } else { j=table[j]; j++; cnt++; } } if(cnt>n/2) { for(int j=l[i];j<=r[i];j++) { table[j]=r[i]; } } } for(int i=1;i<maxn;i++) { if(color[i]!=color[i-1]&&color[i]!=-1) ans[color[i]]++; } for(int i=0;i<=maxn;i++) if(ans[i]) printf("%d %d\n",i,ans[i]); printf("\n"); }}
0 0
- POJ 2528 Mayor's posters+zoj 1610 Count the Colors(数组记录)
- poj 2528 Mayor's posters(树状数组+离散化)
- POJ 2528 Mayor's posters
- poj 2528 Mayor's posters
- POJ 2528 Mayor's Posters
- Mayor's posters poj 2528
- poj 2528 Mayor's posters
- Poj 2528 Mayor's posters
- poj 2528 Mayor's posters
- POJ 2528 Mayor's posters
- POJ 2528 Mayor's posters
- POJ 2528 - Mayor's posters
- POJ-2528-Mayor's posters
- poj 2528 Mayor's posters
- poj 2528 Mayor's posters
- poj 2528 Mayor's posters
- POJ 2528 Mayor's posters
- POJ 2528 Mayor's posters
- 软件开发中最顶级的 17 个平台和工具
- linux之VM虚拟机网络问题
- Mybatis 3.0 参数的传递
- JavaScript获取本地城市和天气预报实现
- iOS证书(.p12)和描述文件(.mobileprovision)申请
- POJ 2528 Mayor's posters+zoj 1610 Count the Colors(数组记录)
- 前端跨域知识总结
- (2.1.1.6)一看你就懂,Java中的ClassLoader详解
- se错题集锦(二)
- 微信公众号项目笔记 二
- 面试感悟----一名3年工作经验的程序员应该具备的技能
- oracle之存储过程5-查询结果保存到变量中去
- 如何理解c++this指针
- 彻底理解 JS 中 this 的指向