链表。

 #include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXM 1001
#define MAXN 100001 int un[MAXM], ub[MAXM];
int v[MAXN];
int next[MAXN]; int comp(const void *a, const void *b) {
return *(int *)a - *(int *)b;
} int main() {
int m, n, t;
int i, j, k;
int ui, bi;
int bid[];
char cmd[]; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d %d", &m, &n) != EOF) {
scanf("%d", &t);
memset(un, , sizeof(un));
memset(ub, , sizeof(ub));
memset(v, , sizeof(v));
while (t--) {
scanf("%s", cmd);
if (cmd[] == 'B') {
// borrow ui bi
scanf("%d %d", &ui, &bi);
if (v[bi]) {
printf("The book is not in the library now\n");
} else if (un[ui] == ) {
printf("You are not allowed to borrow any more\n");
} else {
v[bi] = ui;
next[bi] = ub[ui];
ub[ui] = bi;
un[ui]++;
printf("Borrow success\n");
}
}
if (cmd[] == 'R') {
// return bi
scanf("%d", &bi);
if (v[bi] == ) {
printf("The book is already in the library\n");
} else {
ui = v[bi];
i = ;
j = ub[ui];
if (j == bi) {
ub[ui] = next[j];
} else {
while (i<un[ui] && bi!=next[j]) {
j = next[j];
++i;
}
next[j] = next[bi];
}
un[ui]--;
v[bi] = ;
printf("Return success\n");
}
}
if (cmd[] == 'Q') {
// query ui
scanf("%d", &ui);
if (un[ui]) {
i = ;
j = ub[ui];
while (i < un[ui]) {
bid[i++] = j;
j = next[j];
}
qsort(bid, un[ui], sizeof(int), comp);
for (i=; i<un[ui]-; ++i)
printf("%d ", bid[i]);
printf("%d\n", bid[i]);
} else {
printf("Empty\n");
}
}
}
printf("\n");
} return ;
}

【HDOJ】1497 Simple Library Management System的更多相关文章

  1. Simple Library Management System HDU - 1497(图书管理系统)

    Problem Description After AC all the hardest problems in the world , the ACboy 8006 now has nothing ...

  2. 【HDOJ】2451 Simple Addition Expression

    递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41- ...

  3. 【HDOJ】1341 Simple Computers

    注意PC要与31. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 40 ...

  4. 【CF802C】Heidi and Library(网络流)

    [CF802C]Heidi and Library(网络流) 题面 CF 洛谷 题解 前面两个Easy和Medium都是什么鬼玩意啊.... 不难发现如果这天的要求就是第\(a_i\)种书的话,那么\ ...

  5. 【BZOJ3489】A simple rmq problem(KD-Tree)

    [BZOJ3489]A simple rmq problem(KD-Tree) 题面 BZOJ 题解 直接做肯定不好做,首先我们知道我们是一个二维平面数点,但是限制区间只能出现一次很不好办,那么我们给 ...

  6. 【CF802C】Heidi and Library (hard) 费用流

    [CF802C]Heidi and Library (hard) 题意:有n个人依次来借书,第i人来的时候要求书店里必须有种类为ai的书,种类为i的书要花费ci块钱购入.而书店的容量只有k,多余的书只 ...

  7. 【BZOJ3489】A simple rmq problem

    [BZOJ3489]A simple rmq problem 题面 bzoj 题解 这个题不强制在线的话随便做啊... 考虑强制在线时怎么搞 预处理出一个位置上一个出现的相同数的位置\(pre\)与下 ...

  8. 【BZOJ3489】A simple rmq problem kd-tree

    [BZOJ3489]A simple rmq problem Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过 ...

  9. 【Winform】 无法将类型为“System.Windows.Forms.SplitContainer”的对象强制转换为类型“System.ComponentModel.ISupportInitialize”。

    问题:将dotnet framework 4.0 切换到2.0时,编译没有问题,在运行时出现如下错误:System.InvalidCastException: 无法将类型为“System.Window ...

随机推荐

  1. ulimit开启coredump时核心转储

    [root@localhost ~]# ulimit -c [root@localhost ~]# ulimit -a core data seg size (kbytes, -d) unlimite ...

  2. 4 Java学习之 反射Reflection

    1. 反射概念  反射机制就是:动态地获取类的一切信息,并利用这些信息做一些你想做的事情. java反射机制能够知道类名而不实例化对象的状态下,获得对象的属性或调用方法. JAVA反射机制是在运行状态 ...

  3. Android 用ping的方法判断当前网络是否可用

    判断网络的情况中,有个比较麻烦的情况就是连上了某个网络,但是那个网络无法上网 ,,, = = 想到了用ping指令来判断,经测试,可行~ ~ ~ private static final boolea ...

  4. 命名空间引用问题 包括找不到ConfigurationManager 这个类

        因为SqlConnection类是属于 System.Data.SqlClient命名空间下的,     所以命名空间引用的时候需要加上 System.Data.SqlClient,代码如下: ...

  5. Linux popen/pclose

    popen() 函数 #include <stdio.h>FILE * popen(const char *command , const char *type );int pclose( ...

  6. 比较好的总结runtime

    http://www.cocoachina.com/ios/20160128/15154.html

  7. el和jstl

    <%@page import="cn.bdqn.bean.News"%> <%@ page language="java" import=&q ...

  8. HTML5中class选择器属性的解释

    设置有class属性值的元素,可以被css中的选择器调用,也可以在javascript中以getElementsByClassName()方法调用. 可以给各个元素添加class而且名称可以相同与id ...

  9. Ps 美白磨皮【1】

      方法一:去色加图层模式法 打开需要编辑的图片,按Ctrl+J复制新的图层1. 点击菜单栏“图像”-“调整”-“去色”,如下图所示. 将图层面板的混合模式更改为“滤色”,如下图4所示. 最后的显示效 ...

  10. 使用Scanner来解析文件

    前面的流是全部流进来再处理,空间换取时间 我们用Scanner来解析文件,先处理再输入数据,时间换取空间 两种方法 Scanner scanner1=new Scanner(file1); for(; ...