POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)

题目链接:

PKU:http://poj.org/problem?id=3654

ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2936

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2723

Description

The Tyrell corporation uses a state-of-the-art electronic document system that controls all aspects of document creation, viewing, editing, and distribution. Document security is handled via access control lists(ACLs). An ACL defines a set of
entities that have access to the document, and for each entity defines the set of rights that it has. Entities are denoted by uppercase letters; an entity might be a single individual or an entire division. Rights are denoted by lowercase letters; examples
of rights are a for appendd for deletee for edit, and r for read.

The ACL for a document is stored along with that document, but there is also a separate ACL log stored on a separate log server. All documents start with an empty ACL, which grants no rights to anyone. Every time the ACL for a document is changed,
a new entry is written to the log. An entry is of the form ExR, where E is a nonempty set of entities, R is a nonempty set of rights, and x is either "+", "–", or "=". Entry E+R says to grant all the rights
in R to all the entities in E, entry ER says to remove all the rights in R from all the entities in E, and entry E=R says that all the entities in E have exactly the rights in R and
no others. An entry might be redundant in the sense that it grants an entity a right it already has and/or denies an entity a right that it doesn‘t have. A log is simply a list of entries separated by commas, ordered chronologically from oldest to most recent.
Entries are cumulative, with newer entries taking precedence over older entries if there is a conflict.

Periodically the Tyrell corporation will run a security check by using the logs to compute the current ACL for each document and then comparing it with the ACL actually stored with the document. A mismatch indicates a security breach. Your job is to write
a program that, given an ACL log, computes the current ACL.

Input

The input consists of one or more ACL logs, each 3–79 characters long and on a line by itself, followed by a line containing only "#" that signals the end of the input. Logs will be in the format defined above and will not contain any whitespace.

Output

For each log, output a single line containing the log number (logs are numbered sequentially starting with one), then a colon, then the current ACL in the format shown below. Note that (1) spaces do not appear in the output; (2) entities are listed in alphabetical
order; (3) the rights for an entity are listed in alphabetical order; (4) entities with no current rights are not listed (even if they appeared in a log entry), so it‘s possible that an ACL will be empty; and (5) if two or more consecutive entities have exactly
the same rights, those rights are only output once, after the list of entities.

Sample Input

MC-p,SC+c
YB=rde,B-dq,AYM+e
GQ+tju,GH-ju,AQ-z,Q=t,QG-t
JBL=fwa,H+wf,LD-fz,BJ-a,P=aw
#

Sample Output

1:CSc
2:AeBerMeYder
3:
4:BHJfwLPaw

Source

Mid-Central USA 2007

题意:

运算符(“‘+’, ‘-’, ‘‘=”)前面是名字,‘+’表示把后面的权力赋给前面的人,‘-’表示从前面的人中减去后面的权力(当然没有就不减),‘=’表示把前面的人的权力先清空在把后面的权力赋给前面的人!输出的时候有相同权力的相邻两个人就名字一起输出,再一起输出权力!如果都没有权力则不输出!

代码如下:

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
const int maxn = 57;
int a[maxn][maxn];

int main()
{
    string tt;
    char str[1017];
    int cas = 0;
    int num[maxn];
    while(scanf("%s",str)!=EOF)
    {
        int len = strlen(str);
        if(len == 1 && str[0] == '#')
            break;
        tt = "";
        memset(a,0,sizeof a);
        for(int i = 0; i < len; i++)
        {
            if(str[i]==',')
                tt = "";//清空
            else if(str[i] == '+')
            {
                for(int j = i+1; str[j]!=',' && j < len; j++)
                {
                    for(int k = 0; k < tt.size(); k++)
                    {
                        a[tt[k]-'A'][str[j]-'a']=1;
                    }
                }
            }
            else if(str[i] == '-')
            {
                for(int j = i+1; str[j]!=',' && j < len; j++)
                {
                    for(int k = 0; k < tt.size(); k++)
                    {
                        a[tt[k]-'A'][str[j]-'a']=0;
                    }
                }
            }
            else if(str[i] == '=')
            {
                for(int k = 0; k < tt.size(); k++)
                {
                    memset(a[tt[k]-'A'],0,sizeof a[0]);
                    for(int j = i+1; str[j]!=',' && j < len; j++)
                    {
                        a[tt[k]-'A'][str[j]-'a']=1;
                    }
                }
            }
            else
                tt+=str[i];
        }
        printf("%d:",++cas);
        int l = 0;
        for(int i = 0; i < 26; i++)//记录下所有有权力的人
        {
            int flag = 0;
            for(int j = 0; j < 26; j++)
            {
                if(a[i][j])
                    flag = 1;
            }
            if(flag)
            {
                num[l++] = i;
            }
        }

        tt = "";
        for(int i = 0; i < l; i++)
        {
            int flag = 0;
            if(i != l-1)
            {
                for(int j = 0; j < 26; j++)
                {
                    if(a[num[i]][j] != a[num[i+1]][j])//所含的权力不同
                    {
                        flag = 1;
                    }
                }
            }
            char tem = 'A'+num[i];
            tt += tem;
            if(flag==1 || i==l-1)
            {
                cout<<tt;
                tt = "";
                for(int j = 0; j < 26; j++)
                {
                    if(a[num[i]][j])
                        printf("%c",'a'+j);
                }
            }
        }
        printf("\n");
    }
    return 0;
}
时间: 2025-01-05 02:38:09

POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)的相关文章

POJ 2777 &amp;&amp; ZOJ 1610 &amp;&amp;HDU 1698 --线段树--区间更新

直接将这3题 放一起了  今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 -- 区间更新的话 分为 增减 或者 修改 主要就是个 laze 标记 就是延迟更新 对于区间更新的写法 一般是有2种 其一 仔细划分到每个细小的区间    另一 粗略划分 反正 ==我的代码里会给出2种写法 看自己喜好 hdu 1 //线段树 成段更新 ---> 替换 根结点的查询 2 3 #i

POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

题目链接: POJ:http://poj.org/problem?id=3100 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1818 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2740 Description Given positive integers B and N, find an integer A such that AN is as close as

POJ 3653 &amp; ZOJ 2935 &amp; HDU 2722 Here We Go(relians) Again(最短路dijstra)

题目链接: PKU:http://poj.org/problem?id=3653 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1934 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2722 Description The Gorelians are a warlike race that travel the universe conquering new world

POJ 3652 &amp; ZOJ 2934 &amp; HDU 2721 Persistent Bits(数学 进制)

题目链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1933 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2721 Description WhatNext Software creates sequence generators that they hope will produce fair

HDU 1116 || POJ 1386 || ZOJ 2016 Play on Words (欧拉回路+并查集)

题目链接 题意 : 有很多门,每个门上有很多磁盘,每个盘上一个单词,必须重新排列磁盘使得每个单词的第一个字母与前一个单词的最后一个字母相同.给你一组单词问能不能排成上述形式. 思路 :把每个单词看成有首字母指向尾字母的有向边,每个字母看成一个点,题中要求等效于判断图中是否存在一条路径经过每一条一次且仅一次,就是有向欧拉通路.统计个顶点的出入度,如果每个点的出入度都相同,那就是欧拉回路,如果有两个奇数度,那就是欧拉通路,除此之外,都不能满足要求.还有别忘了判断是否连通,此时用到并查集,图中所有的边

ZOJ 2562 HDU 4228 反素数

反素数: 对于任何正整数x,起约数的个数记做g(x).例如g(1)=1,g(6)=4. 如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数. ZOJ 2562 反素数 因为写了POJ 2886的线段树,然后里面有反素数,以前没遇到过,所以先搞这两题普及一下知识再说. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&

POJ 2135 Farm Tour &amp;&amp; HDU 2686 Matrix &amp;&amp; HDU 3376 Matrix Again 费用流求来回最短路

累了就要写题解,最近总是被虐到没脾气. 来回最短路问题貌似也可以用DP来搞,不过拿费用流还是很方便的. 可以转化成求满流为2 的最小花费.一般做法为拆点,对于 i 拆为2*i 和 2*i+1,然后连一条流量为1(花费根据题意来定) 的边来控制每个点只能通过一次. 额外添加source和sink来控制满流为2. 代码都雷同,以HDU3376为例. #include <algorithm> #include <iostream> #include <cstring> #in

ZOJ 3048 (HDU 2258) Continuous Same Game (1)

Problem Description Continuous Same Game is a simple game played on a grid of colored blocks. Groups of two or more connected (orthogonally, not diagonally) blocks that are the same color may be removed from the board. When a group of blocks is remov

poj 1979 &amp;&amp; zoj 2165 Red and Black

Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22409   Accepted: 12100 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a