zoj1610
来源:互联网 发布:大数据对驾校的影响 编辑:程序博客网 时间:2024/06/05 18:19
题目大意:
在一条线上涂颜色,以前某一段的颜色可能被后来的覆盖。
你的任务是数数最后你可以看见多少种颜色
输入:x1 x2 c
x1和x2分别代表段的两端,c代表颜色
解题思路:
线段树问题
代码如下:
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;const int maxes=20001;int temp;struct node{ int left; int right; int kind;}segtree[maxes];int color[8001];void creat_tree(int n,int l,int r){ segtree[n].left=l; segtree[n].right=r; segtree[n].kind=-1; if(l+1==r) return; int mid=(l+r)>>1; creat_tree(n*2,l,mid); creat_tree(n*2+1,mid,r);}void insert_tree(int n,int l,int r,int c){ if(l==r) return; if(segtree[n].kind==c) return; if(l<=segtree[n].left&&segtree[n].right<=r) { segtree[n].kind=c; return; } if(segtree[n].kind>=0) { segtree[n*2].kind=segtree[n].kind; segtree[n*2+1].kind=segtree[n].kind; segtree[n].kind=-2; } int mid=(segtree[n].left+segtree[n].right)>>1; if(r<=mid) { insert_tree(n*2,l,r,c); } else if(l>=mid) { insert_tree(n*2+1,l,r,c); } else { insert_tree(n*2,l,mid,c); insert_tree(n*2+1,mid,r,c); }}void count(int n){ if(segtree[n].kind!=-1&&segtree[n].kind!=-2) { if(segtree[n].kind!=temp) { color[segtree[n].kind]++; temp=segtree[n].kind; } return; } if(segtree[n].left+1!=segtree[n].right) { count(n*2); count(n*2+1); } else temp=-1;}int main(){ int i,t,a,b,c; while(scanf("%d",&t)!=EOF) { creat_tree(1,0,8000); while(t--) { scanf("%d%d%d",&a,&b,&c); insert_tree(1,a,b,c); } temp=-1; memset(color,0,sizeof(color)); count(1); for(i=0;i<=8000;i++) { if(color[i]) printf("%d %d\n",i,color[i]); } printf("\n"); } return 0;}
0 0
- zoj1610
- zoj1610
- ZOJ1610【未完成】
- ZOJ1610+线段树
- ZOJ1610-Count the Colors
- zoj1610-Count the Colors
- ZOJ1610 Count the Colors
- ZOJ1610-Count the Colors
- zoj1610:count the colors
- just a hook hdu1698+zoj1610
- ZOJ1610 Count the Colors,线段树
- 线段树:ZOJ1610、ZOJ3635、ZOJ3633、ZOJ3349
- [Virtual Judge]ZOJ1610:Count the Colors
- zoj1610(线段树成段覆盖,lazy标记)
- ZOJ1610——Count the Colors
- zoj1610 Count the Colors(线段树)
- 线段树之ZOJ1610 Count the Colors
- zoj1610( 线段树)(Count the Colors)
- 留住人才的不是高薪,而是认可
- 水果编曲软件除了做电音还能做什么
- Android中的inputType属性简单用法.
- Android 如何监听App的输入了那些内容
- SpringMVC下处理请求(配置Controller)
- zoj1610
- 1012. The Best Rank (25)
- 关键词抽取(keywords extraction)的相关研究
- Jquery动态添加行
- Android HTTPS请求总结
- 纯CSS实现图片水平垂直居中于DIV(图片未知宽高)
- Android应用启动黑屏、白屏解决方法
- 域名解析基础知识(NS,A记录,CNAME,MX)
- zoj1619