POJ3225 Help with Intervals
来源:互联网 发布:怎么注册国外域名 编辑:程序博客网 时间:2024/05/21 03:03
Description
LogLoader, Inc. is a company specialized in providing products for analyzing logs. While Ikki is working on graduation design, he is also engaged in an internship at LogLoader. Among his tasks, one is to write a module for manipulating time intervals, which have confused him a lot. Now he badly needs your help.
In discrete mathematics, you have studied several basic set operations, namely union, intersection, relative complementation and symmetric difference, which naturally apply to the specialization of sets as intervals.. For your quick reference they are summarized in the table below:
Operation Notation UnionA ∪ B{x : x ∈ A or x ∈ B}IntersectionA ∩ B{x : x ∈ A and x ∈ B}Relative complementationA − B{x : x ∈ A but x ∉ B}Symmetric differenceA ⊕ B(A − B) ∪ (B − A) Definition
Ikki has abstracted the interval operations emerging from his job as a tiny programming language. He wants you to implement an interpreter for him. The language maintains a set S, which starts out empty and is modified as specified by the following commands:
Command Semantics U
TS ← S ∪ TI
TS ← S ∩ TD
TS ← S − TC
TS ← T − SS
TS ← S ⊕ T
Input
The input contains exactly one test case, which consists of between 0 and 65,535 (inclusive) commands of the language. Each command occupies a single line and appears like
X
T
where X
is one of ‘U
’, ‘I
’, ‘D
’, ‘C
’ and ‘S
’ and T is an interval in one of the forms (
a,
b)
, (
a,
b]
, [
a,
b)
and [
a,
b]
(a, b ∈ Z, 0 ≤ a ≤ b ≤ 65,535), which take their usual meanings. The commands are executed in the order they appear in the input.
End of file (EOF) indicates the end of input.
Output
Output the set S as it is after the last command is executed as the union of a minimal collection of disjoint intervals. The intervals should be printed on one line separated by single spaces and appear in increasing order of their endpoints. If S is empty, just print “empty set
” and nothing else.
Sample Input
U [1,5]D [3,3]S [2,4]C (1,5)I (2,3]
Sample Output
(2,3)
题目大意:
将一个空集进行题目所给出的5种操作,输出最终集合。
题解:
#include <cstdio>#include <iostream>using namespace std;#define lx (x<<1)#define rx ((x<<1)|1)#define mid ((l+r)>>1)const int N = 65535 + 10 << 1;int num[N<<2], Xor[N<<2];bool now[N+10];int X, Y;char q[1];void pxor(int x){ if(num[x] != -1) num[x] ^= 1; else Xor[x] ^= 1;}void push_down(int x){ if(num[x] != -1){ num[lx] = num[rx] = num[x]; Xor[lx] = Xor[rx] = 0; num[x] = -1; } if(Xor[x]){ pxor(lx); pxor(rx); Xor[x] = 0; }}void update(int l, int r, int x){ if(X <= l && r <= Y){ if(q[0] == 'U') { num[x] = 1; Xor[x] = 0; } else if(q[0] == 'D'){ num[x] = 0; Xor[x] = 0; } else if(q[0] == 'C' || q[0] == 'S') pxor(x); return; } push_down(x); if(X <= mid) update(l, mid, lx); else if(q[0] == 'I' || q[0] == 'C') num[lx] = Xor[lx] = 0; if(Y > mid) update(mid+1, r, rx); else if(q[0] == 'I' || q[0] == 'C') num[rx] = Xor[rx] = 0;}void query(int l, int r, int x){ if(num[x] == 1){ for(int i = l; i <= r; i++) now[i] = 1; return; } else if(num[x] == 0) return; if(l == r) return; push_down(x); query(l, mid, lx); query(mid+1, r, rx);}int main(){ char lc, rc; int a, b; while(~scanf("%s %c%d,%d%c\n", q, &lc, &a, &b, &rc)){ X = a << 1; Y = b << 1; if(lc == '(') X++; if(rc == ')') Y--; update(0, N, 1); } query(0, N, 1); a = -1; bool flag = false; for(int i = 0; i <= N; i++){ if(now[i]){ if(a == -1) a = i; b = i; } else{ if(a != -1){ if(flag) putchar(' '); printf("%c%d,%d%c",a&1?'(':'[', a>>1, (b+1)>>1, b&1?')':']'); a = -1; flag = true; } } } if(!flag) puts("empty set"); else puts(""); return 0;}
- POJ3225--Help with Intervals
- poj3225 Help with Intervals
- poj3225 Help with Intervals
- 【poj3225】Help with Intervals
- POJ3225 Help with Intervals
- poj3225 Help with Intervals 线段树 区间交并补
- POJ3225 Help with Intervals 线段树区间更新
- poj3225 Help with Intervals 线段树,成段更新,TLE,求指教。。本人提供测试数据~
- 3225 Help with Intervals
- POJ 3225 - Help with Intervals
- POJ 3225 - Help with Intervals
- POJ 3225 Help with Intervals
- Poj 3225 Help with Intervals
- POJ 3225 Help with Intervals
- POJ 3225 Help with Intervals
- poj-3225-Help with Intervals
- POJ-3225 Help with Intervals
- poj 3225 Help with Intervals
- Spring MVC 4 + Spring Security 4 + Hibernate +JPA实战
- vector 计算数组中的最大值 最小值
- Java学习重点易忽略问题整理
- [AHK]华泰通达信交易客户端锁定后自动解锁
- sql语句查询各门课程平均分的最大值
- POJ3225 Help with Intervals
- Thinking in Java(8)-Behavior of Polymorphic methods inside constructors
- quartz CronExpression表达式
- 经典.net面试题目
- Linux设备驱动之UART驱动结构
- vpn的作用和特点
- 【JZOJ 4915】最长不下降子序列
- Android高级之十三讲之安全方案
- 通过反射机制获取位于同一个包下的接口的所有实现类