Poj--2155(二维线段树)

2014-09-26 02:21:14

思路:初写二维线段树,把点查询当成区间查询也是智压了QAQ。参考:http://www.cnblogs.com/gj-Acit/p/3258880.html

 1 /*************************************************************************
 2     > File Name: p2155.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Fri 26 Sep 2014 01:09:19 AM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <queue>
14 #include <iostream>
15 #include <algorithm>
16 using namespace std;
17 typedef long long ll;
18 #define lpos pos << 1
19 #define rpos pos << 1|1
20 #define getmid(l,r) (l + (r - l) / 2)
21 const int INF = 1 << 29;
22 const int maxn = 1010;
23 
24 bool tree[maxn << 2][maxn << 2];
25 int X1,Y1,X2,Y2,cnt;
26 int N,T,Case;
27 
28 void Update_y(int xpos,int ypos,int l,int r){
29     if(Y1 <= l && r <= Y2){
30         tree[xpos][ypos] = !tree[xpos][ypos];
31         return;
32     }
33     int mid = getmid(l,r);
34     if(Y1 <= mid) Update_y(xpos,ypos << 1,l,mid);
35     if(Y2 > mid) Update_y(xpos,ypos << 1|1,mid + 1,r);
36 }
37 
38 void Update_x(int pos,int l,int r){
39     if(X1 <= l && r <= X2){
40         Update_y(pos,1,1,N);
41         return;
42     }
43     int mid = getmid(l,r);
44     if(X1 <= mid) Update_x(lpos,l,mid);
45     if(X2 > mid) Update_x(rpos,mid + 1,r);
46 }
47 
48 void Query_y(int xpos,int ypos,int l,int r){
49     if(tree[xpos][ypos])
50         ++cnt;
51     if(l == r)
52         return;
53     int mid = getmid(l,r);
54     if(Y1 <= mid) Query_y(xpos,ypos << 1,l,mid);
55     else Query_y(xpos,ypos << 1|1,mid + 1,r);
56 }    
57 
58 void Query_x(int pos,int l,int r){
59     Query_y(pos,1,1,N);
60     if(l == r)
61         return;
62     int mid = getmid(l,r);
63     if(X1 <= mid) Query_x(pos << 1,l,mid);
64     else Query_x(pos << 1|1,mid + 1,r);
65 }
66 
67 int main(){
68     char s[5];
69     scanf("%d",&Case);
70     while(Case--){
71         memset(tree,false,sizeof(tree));
72         scanf("%d%d",&N,&T);
73         while(T--){
74             scanf("%s",s);
75             if(s[0] == 'C'){
76                 scanf("%d%d%d%d",&X1,&Y1,&X2,&Y2);
77                 Update_x(1,1,N);
78             }
79             else{
80                 scanf("%d%d",&X1,&Y1);
81                 cnt = 0;
82                  Query_x(1,1,N);
83                 if(cnt & 1) printf("1\n");
84                 else printf("0\n");
85             }
86         }
87         if(Case) puts("");
88     }
89     return 0;
90 }

 

转载于:https://www.cnblogs.com/naturepengchen/articles/3994042.html

【从高压输电线的架空地线中汲取电能】一个25千瓦受控电源从735千伏线路的架空地线中汲取电能的SimPowerSystems模型(Simulink仿真实现)内容概要:本文介绍了一个基于SimPowerSystems的Simulink仿真模型,用于模拟从735千伏高压输电线的架空地线中汲取25千瓦电能的受控电源系统。该模型聚焦于高压输电线路中架空地线的能量回收技术,通过仿真手段实现对电能采集过程的建模与控制策略验证,体现了电力系统中新型能源获取方式的技术可行性与工程应用潜力。文中还提及该资源属于一系列电力系统仿真研究的一部分,涵盖微电网、储能优化、碳流追踪、鲁棒调度等多个前沿方向,配套提供Matlab/Simulink代码及网盘资料链接,便于科研人员复现与拓展研究。; 适合人群:具备电力系统基础知识、熟悉Matlab/Simulink仿真环境,从事电力工程、能源回收或智能电网相关研究的科研人员及研究生;有一定编程与建模仿真经验的高年级本科生或工程技术人员。; 使用场景及目标:①研究高压输电线路中架空地线的能量回收机制与建模方法;②掌握基于Simulink的电力系统仿真技术,特别是受控电源与电网交互的动态特性分析;③为开展能源 harvesting、分布式供能、电力电子变换器控制等相关课题提供参考模型与技术支撑; 阅读建议:建议结合提供的仿真模型文件进行实操演练,重点理解系统结构设计、参数设置与控制逻辑实现;同时可延伸学习文档中提到的其他电力系统优化与仿真案例,以拓宽研究视野和技术积累。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值