ZOJ1610 Count the Colors,线段树

COMSOL实战:如何用有限元法(FEM)准确仿真电磁场问题?避坑指南 本文是一份COMSOL电磁场仿真实战指南,重点讲解如何运用有限元法(FEM)准确模拟电磁场问题。文章通过矩形波导和偶极子天线两大经典案例,详细剖析了从几何建模、物理场设置、网格剖分到结果验证的全流程,并提供了处理非线性材料、求解器收敛失败等高级问题的避坑技巧,旨在帮助工程师建立可靠的仿真工作流。 阅读详情

以前做过,现在用线段树来做,主要参考这个:请猛击我!


/*******************************************************************************
 # Author : Neo Fung
 # Email : neosfung@gmail.com
 # Last modified: 2012-01-17 18:47
 # Filename: ZOJ1610 Count the Colors 线段树版.cpp
 # Description : 
 ******************************************************************************/
#ifdef _MSC_VER
#define DEBUG
#endif

#include <fstream>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <functional>
#include <ctype.h>
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MAX 8010
using namespace std;

struct NODE_T
{int l,r,color;}node[MAX*3];

int color[MAX],len[MAX];

void init()
{
	memset(node,'\0',sizeof(node));
	memset(color,-1,sizeof(color));
	memset(len,0,sizeof(len));
}

void build(const int &t,const int &l,const int &r)
{
	node[t].l=l;
	node[t].r=r;
	node[t].color=-1;
	if(l==r-1) return;
	int mid = (l+r)>>1;
	build(L(t),l,mid);
	build(R(t),mid,r);
}

void Update(const int &t,const int &l,const int &r,const int &color)
{
	if(node[t].l>=l && node[t].r<=r)
	{
		node[t].color = color;
		return;
	}
	if(node[t].color == color)
		return;
	if(node[t].color>=0)
	{
		node[L(t)].color = node[t].color;
		node[R(t)].color =  node[t].color;
		node[t].color = -1;
	}
	int mid = (node[t].l+node[t].r)>>1;
	if(l>=mid)
		Update(R(t),l,r,color);
	else if(r<=mid)
		Update(L(t),l,r,color);
	else
	{
		Update(L(t),l,mid,color);
		Update(R(t),mid,r,color);
	}
}

void compute(const int &t,const int &l,const int &r)
{
	if(node[t].color>=0)
	{
		for(int i=l;i<r;++i)
			color[i]=node[t].color;
		return;
	}
	if(node[t].l==node[t].r-1)
		return;
	int mid = (node[t].l+node[t].r)>>1;
	if(l>=mid)
		compute(R(t),l,r);
	else if(r<=mid)
		compute(L(t),l,r);
	else
	{
		compute(L(t),l,mid);
		compute(R(t),mid,r);
	}
}

int main(void)
{
#ifdef DEBUG  
  freopen("../stdin.txt","r",stdin);
  freopen("../stdout.txt","w",stdout); 
#endif  
  int n,x,y,col;
  while(~scanf("%d",&n))
  {
	  init();
	  build(1,0,8000);
	  while(n--)
	  {
		  scanf("%d%d%d",&x,&y,&col);
		  Update(1,x,y,col);
	  }
	  compute(1,0,8000);
	  for(int i=0;i<MAX-1;++i)
		  if(color[i+1]!=color[i] && color[i]!=-1)
			  ++len[color[i]];

	  for(int i=0;i<MAX;++i)
		  if(len[i])
			  printf("%d %d\n",i,len[i]);
	  printf("\n");
  }

  return 0;
}



PX4实战(十):PX4导航模块(Navigator)详解 本文将对 PX4 固件 v1.14.3 版本中的 Navigator(导航)模块进行详尽的技术剖析。作为飞行控制栈中的高层决策核心,Navigator 模块承担着将抽象的任务指令转化为具象的底层控制设定点的关键职责。本文基于对 src/modules/navigator 目录下源代码的深究研究与架构反推,详细阐述了该模块的文件组织结构、基于状态机的控制逻辑、uORB 异步通讯机制、核心任务模式(Mission)与返航模式(RTL)的实现细节,以及地理围栏(Geofence)与任务可行性检查(Feasibil 阅读详情

相关推荐

V-rep机器人仿真(Win10):UR5+RG2+Kinect+YOLOV3+DDPG+Pytorch(第四部分:YOLOV3图像识别)

这是一个V-rep机器人仿真实验,较为简单,适合初学者在入门图像识别、机器学习、机器人学的内容时进行学习与训练。 实验涉及的内容有:V-rep机器人仿真,YOLOV3图像识别,强化学习DDPG,UR5机械臂及RG2机械手,Kinect摄像头。 使用环境:Win10,Pytorch0.4,V-rep 整个实验一共由多篇文章组成,本文是第四部分。 第四部分:YOLOV3图像识别 文章目录第四部分:YO...

weixin_42158966的博客 5842

ZOJ 1610 Count the Colors(线段树经典)

Count the Colors Time Limit: 2000 msMemory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can see at last.

深秋无痕 613

初识数据结构之入门必懂——线性表(顺序表)

本文将介绍数据结构中的线性表与线性表中最简单的结构——顺序表

m0_64705485的博客 909

线段树增强训练题 ZOJ1610 Count the Colors

线段树增强训练题 ZOJ1610 Count the Colors 线段树增强训练,啊啊啊,我还是太菜了 这道题调试起码4个小时,明明一道很简单的题目。。。。 题意也看了好久,与一开始还读错题意了,但是问题不大,在原来的代码上改改也可 题意:对一段长为8000的线段进行染色,颜色有8000种,每次对区间[l,r]进行染色,进行n次操作后,问你每一种颜色有几段。 很明显的区间修改和查询,不假思索就...

qq_33437973的博客 233

FCN---训练cityspaces

未经允许,不要随意转载! 最近想试试用FCN训练自己的数据集,想想标注是一件很费劲的事,于是就想到了用其他库里的数据,这里选用了cityspaces,默认已经配置好FCN. 1、下载cityspaces https://www.cityscapes-dataset.com/ 需要注册一个账号 cityspaces包含2...

wangyu088的专栏 2042

【YOLOv8全方位学习手册】第四章 数据增强:从扩充数据到塑造模型的认知边界

"""使用 Albumentations 做自定义增强,兼容 YOLO 格式"""])# 转成 numpy# boxes 必须是 [[x_min,y_min,x_max,y_max], ...]# 在数据加载时调用你可以把集成到 PyTorch 的 Dataset 类里,或使用 Ultralytics 自带的DataLoader。

VectorShift的博客 214

ZOJ - 1610 Count the Colors(模拟,线段树)

vjudge链接https://vjudge.csgrandeur.cn/problem/ZOJ-1610 ZOJ官方链接https://zoj.pintia.cn/problem-sets/91827364500/problems/91827365109 #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N = 8010; int a[N], colo

00后的博客 457

构建.NET网站:VSCode还是Visual Studio?揭开开发工具的选择之谜

选择VSCode还是Visual Studio,归根结底是取决于你的具体需求和偏好。🔍 这两款工具各有千秋,都能为你的.NET网站开发提供强大的支持。希望这篇文章能够帮助你更全面地了解这两款工具,做出明智的选择。

墨夶的博客 792

ZOJ 1610 Count the Colors【线段树】

Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.

wyjwyl的专栏 436

【STK】手把手教你利用STK进行进行光电红外仿真02-STK/EOIR模块属性之一 传感器选项设置

EOIR传感器可以从空间几何属性、光谱属性、光学属性、辐射属性四个方面进行设置,并且可以设置信号传播路径中的大气特性,包括大气模型、气溶胶模型、气象学可见性和大气湿度。在定义EOIR传感器时,需要Sensor——Definition属性页中,将Sensor Type设置为EOIR。单击下面的按钮打开传感器的EOIR配置页,可以对传感器的属性进行配置,此外,还可以在场景中视情况添加相关的中心体。路径辐射损耗影响上述特性的计算,计算的结果考虑了传感器、目标位置的影响,但是还没考虑地球临边背景的影响。

weixin_44184852的博客 3208

PCL Fast Global Registration 快速全局配准(源码版)

Fast Global Registration(FGR)是一种经典的点云粗配准算法,已集成到Open3D和CloudCompare等软件中。本文介绍了该算法的源码实现及优化方法,包括如何通过修改源码直接读取点云进行配准,而不依赖文件中读取特征描述子。文章还提供了关键参数设置(如最大迭代次数、匹配距离等)。算法实现简单高效,未来计划发布基于纯PCL的版本。源码和论文链接已附上,供开发者参考。

点云侠的博客 385

ZOJ 1610 Count the Colors 线段树 染色问题

做法:在udate之后可以直接把线段树上的信息映射到一个数组上考虑 #include #include #define left l,m,x<<1 #define right m+1,r,x<<1|1 const int LMT=16002; int cov[LMT<<2],seg[LMT],ans[LMT]; //映射法 void init(void) { memset(cov,-1,siz

uiiの技术随笔 760

【C++STL基础入门】stack栈的基础使用

C++ STL(Standard Template Library)是C++标准库中的一个强大的工具集,提供了各种常用的数据结构和算法。其中之一就是Stack(栈),是一种后进先出(LIFO)的数据结构。使用栈可以很方便地管理数据的顺序,它具有简单、高效和易于使用的特点。本文将介绍Stack栈的基础使用方法,帮助初学者快速掌握它的概念和用法。本文简要介绍了C++ STL中Stack栈的基础使用方法。

m0_62599305的博客 3999

【线段树】Count the Colors (zoj 1610)

Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB (zoj 1610) Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent on

Jiangzh_MZOI 761

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

zoj1610 Count the Colors 线段树

题目链接在这里 题目描述: 在一条直线上画不同颜色的线段,给出各线段的起点、终点和颜色,求画完之后,最终会有几种颜色,每个颜色有多少条线段。 思路分析: 我们用线段树保存各点的颜色,区间更新,最后query一下就好。 注意题目给的是线段的起点和终点,是连续的。如果想用离散的表示的话,就让起点+1,代表一段。 代码如下: 非结构体: #include &lt;cstdio&gt; ...

Joel 235

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

zoj1610Count the Colors【暴力 or 线段树】

ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the

走一步再走一步 736

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

zoj 1610 Count the Colors 线段树

本地跑不起来交上去能过.. #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r

uuuuuu 506

zoj 1610 Count the Colors 线段树,成段更新染色

Count the ColorsTime Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu SubmitStatus Description Painting some colored segments on a line, some previously painted segments may

colorfulshark 1563

ZOJ 1610 Count the Colors 线段树区间染色问题

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=66989#problem/F 题意:给一个区间范围,然后逐步给某些区间染色,最后问能各种能看见的颜色的块数。典型的线段树染色问题,看了别人的代码不太能理解。但是想到了一个不错的思路。 解题思路:我们可以这样想,显然每条线段最后的颜色都由改线段最后一次的染色决定,如果我们把每一

catch_catch的专栏 1344

线段树之ZOJ1610 Count the Colors

成段替换的模型。 这一题告诉你的是要涂色的点的范围,而线段树内节点表示的区间的颜色(原谅我拙计的语文)。可以和POJ2528 对比,就能发现区别了。 #include #include #include #include #include #include #include #include #include #include #include #include #in

htw 267

Count the Colors (ZOJ - 1610,离散化 + 线段树)

一.题目链接: ZOJ-1610 二.题目大意: 一条线上,端点编号为 [0,8e3]. 每次给出一段区间 和 一种颜色编号,在线上的这段区间染色. 问每种颜色出现的次数. 三.分析: 这道题(记为 Q1)与这道题(记为 Q2)不太一样 画个图理解一下: 可以看到对于 Q1 来说,[3, 4] 区间内为红色,但是节点 3 与 节点 4 相邻,此时不好判断 而 Q2 不存在...

The___Flash的博客 256

zoj 1610 Count the Colors(线段树)

做了大概四个小时,还是参考的别人的,最终才搞定,感觉这题坑太多。 开始建树的时候按照给的n建的树,后来仔细想了下,这错的离谱,这是我的锅,,然后染色的时候,如果给的是x1,x2,c,更新时应该x1+1,x2,c,比如0,4,4,0到4染色4段,也就是染色1到4这四个点。。。在计算某个颜色出现的次数的时候,计算的是颜色段的个数,我起初算的竟然是长度,我的锅。。。。 代码是在vjudge上参考的一个

梦幻的蔷薇色 553

【线段树】Zoj 1610 Count the Colors

题意: 在一条线上绘制一些彩色的线段,某些先前绘制的线段可能会被后续的线段覆盖。 您的任务是计算最终可以看到的不同颜色的分段的数量。 解析: 用点 i+1 来表示线段[ i , i+1 ] #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int maxn = 8000 + 10; int t,m,n,a,b,c,q,k; string s; int su

weixin_44745441的博客 181

线段树专题—ZOJ1610 Count the Colors

题意:给一个n,代表n次操作,接下来每次操作表示把[l。r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可是会给人一种区间合并的错觉 注意:这题比較坑的是千万不能拿n建树,不然就会s...

aoe41606的博客 108

[zoj 1610线段树]F - Count the Colors

color[l,r]表示区间[l,r]被成何种颜色, 不停更新区间颜色,最后查询每个点的颜色,如果该点颜色!=-1也不与前驱相同,则对应颜色结果加1 #include<bits/stdc++.h> using namespace std; #define lc(x) (x<<1) #define rc(x) ((x<<1)|1) const int N = 8000 + 5; int color[N<<2]; void down(int rt){ if(co

我们仍未知道那天所看见的花的名字。 190

ZOJ 1610 Count the Colors(线段树)

Count the ColorsTime Limit: 2 Seconds      Memory Limit: 65536 KBPainting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.Your task is coun...

←_← 212
上一篇: ZOJ3518 Unsafe Factor
下一篇: HDU1754 I Hate It,线段树
neofung
博客等级 码龄19年 81粉丝 216原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值