HDU

来源:互联网 发布:淘宝第三方支付平台 编辑:程序博客网 时间:2024/06/17 19:05
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 append, d for delete, e 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 E–R 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+cYB=rde,B-dq,AYM+eGQ+tju,GH-ju,AQ-z,Q=t,QG-tJBL=fwa,H+wf,LD-fz,BJ-a,P=aw#
Sample Output
1:CSc2:AeBerMeYder3:4:BHJfwLPaw
哇···  QAQ,写了两个小时的模拟,整个学校的智商都被我拉低了,一遇到模拟题就怂,没有任何算法可言,就是利用非常暴力的方法,真的是暴力暴力秒天秒地,最后一发过,估计是数据太水了吧。
题意如下:
额-_-,题意吧,就是ExR型的操作,E代表用户,R表示权限,x代表三种操作(即‘-’‘+’‘=’),- 表示将用户E的权限R去掉,+ 表示给用户E加上权限R,= 表示重新给用户E授权R(以前的权限清除),这里要记住每个逗号隔开是一组ExR型的输入,E和R输入都不唯一,有可能多个权限对多个用户操作,实践是检验真理的唯一标准,说那么多不如解释一下样例来的实际,就解释一下第四个样例吧:
样例四:JBL=fwa,H+wf,LD-fz,BJ-a,P=aw
JBL=fwa 表示将用户JBL的权限重置,然后把权限fwa授给JBL
H+wf    表示将用户H的权限再加上wf两种权限
LD-fz   表示取消用户L和D的fz两种权限
BJ-a    表示取消用户B和J的a权限
P=aw    表示将用户P的权限重置,然后把权限aw授给P
最后把拥有权限的用户按照字典序输出来,有一点,相邻的用户如果权限一样,那么将会写在一起,比如样例一:不是1:CcSc,而是1:CSc
思路嘛,就是模拟了,能看懂代码就看吧。。。
//HDU 2723#include <map>#include <set>#include <cmath>#include <queue>#include <string>#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define inf 0x3f3f3f3f#define eps 1e-10#define maxn 100005#define zero(a) fabs(a)<eps#define Min(a,b) ((a)<(b)?(a):(b))#define Max(a,b) ((a)>(b)?(a):(b))#define pb(a) push_back(a)#define mem(a,b) memset(a,b,sizeof(a))#define LL long long#define lson step<<1#define rson step<<1|1#define MOD 1000000009#define sqr(a) ((a)*(a))using namespace std;char s[1050];int a[28][28];int main() {int m;//长度 int count = 1;char E[105];//代表授给权限的人 E char R[105];//代表所授的权限R while(~scanf("%s",s) && s[0] != '#') {m = strlen(s);mem(a , 0);int i = 0;for(; i < m; i++) {               //一个比较繁琐的循环 if(i == 0 || s[i] == ',') {   //当i=0或者s[i]=','的时候开始一段新的ExR int j = i , e = 0 , r = 0;//e 是E[]的下标, r 是R[]的下标 if(s[i] == ',') j++;      // 如果是逗号就开始新的授权,即j++ for(; j < m; j++) {if(s[j] >= 'A' && s[j] <= 'Z')E[e++] = s[j];        //把授给权限的人记录下来 else break;}int t = -1;if(s[j] == '-') t = 0;      // 0:-  1:+   2:=else if(s[j] == '+') t = 1; // 此处用于记录操作是增加还是减少或者重置权限; else t = 2;j++;                        //j++ 开始记录所授的权限 for(; j < m; j++) {if(s[j] >= 'a' && s[j] <= 'z') {R[r++] = s[j];}else break;}//以上把E存在了E[]里,把R存在了R[]里; if(t == 0) {         //减少权限操作 for(int I = 0; I < r; I++) {for(int J = 0; J < e; J++) {a[R[I]-'a'+1][E[J]-'A'+1] = 0;  //把拥有权限的用户以及权限存在二维数组里 }}}else if(t == 1) {    //增加权限操作 for(int I = 0; I < r; I++) {for(int J = 0; J < e; J++) {a[R[I]-'a'+1][E[J]-'A'+1] = 1;}}}else if(t == 2){      //重置权限操作 for(int I = 0; I < 28; I++) {for(int J = 0; J < e; J++) {a[I][E[J]-'A'+1] = 0;}}for(int I = 0; I < r; I++) {for(int J = 0; J < e; J++) {a[R[I]-'a'+1][E[J]-'A'+1] = 1;}}}}}int t = 1;int AC[1005];for(int j = 0; j < 28; j++) {for(i = 0; i < 28; i++)if(a[i][j]) {AC[t++]  = j;     //将所有的用户给记录下来 }}printf("%d:",count++);t = unique(AC+1,AC+t)-AC;//用于把记录下来的用户去重 int temp;                //标记 for(int j = 1; j < t; j++) {if(AC[j]) {printf("%c",AC[j]-1+'A');}for(int k = j+1; k < t; k++) {temp = 1;for(int l = 1; l < 27; l++) {if(a[l][AC[j]] != a[l][AC[k]]) {  //进行匹配; temp = 0;break;}}if(temp == 1 && AC[k]) {printf("%c",AC[k]-1+'A');AC[k]=0;}else break;}for(int k = 0; k < 28; k++) {if(a[k][AC[j]]) {printf("%c",k-1+'a');}}}printf("\n");}return 0;}


阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 金粉世家免费观看 金粉世家吊顶价格 金粉多少钱一斤 金粉世家包包如何 金粉世家钱包 金粉世家每个人的结局 金粉公子传说 铜金粉多少钱一吨 金粉的使用方法 金粉哪里有卖的 哪有卖金粉的 哪里有金粉卖 金云母粉价格 金艾陶 金胆粉 金胆粉的功效与作用 金红 金纳多片 金纳多片说明书 金纳多片多少钱一盒 金纳多 金纳多说明书 金迷纸醉 工行纸钯金实时价格走势图 纸钯金价格走势图 金纸莲花塔折法18张 纸钯金走势图 金纸 纸迷金醉 纸迷金醉还是纸醉金迷 金纸莲花座折法步骤图解 一吨金纸能出多少元宝 金纸莲花塔底座折法18张 12瓣金纸莲花盆的折法图解 纸碎金迷 白色烫金纸 金旗舰复印纸 汤金纸 金纸素材 面如金纸 销金纸