链表。

 #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. NGUI 动态字体边缘模糊,毛边的问题解决办法

    NGUI支持生成动态字体,将ttf格式的字体文件拖入工程,用NGUIFontMaker制作即可,但是制作完之后会发现字体有毛边,边缘模糊. 这时选中你生成的字体预设,在该预设的UIFont脚本上更改P ...

  2. 告诉你LTE-FDD与LTE-TDD的区别

    [PConline 技术分析]移动早在去年已经拿下了TD-LTE的4G牌照,而中国联通与中国电信的FDD-LTE的牌照在近日正式拿下,而对于4G网络,有多少真正了解呢?接下来笔者就为大家解释一下4G的 ...

  3. 零基础学习IOS开发(二)- 使用cocos2d-x3.0 执行Hello world

    关于开发框架,依据网上检索来的信息,感觉cocos2d-x的ios游戏开发框架非常不错,并且有非常强的可移植性,因此打算尝试一下. 截止写下此文章,最新的cocos2d-x的版本号为v3.0稳定版(几 ...

  4. git clone之后自动checkout文件处理

    这个问题发生是因为不同操作系统的行结束符不一致导致的,可在clone之后在仓库根目录修改.gitattributes文件 简单处理的话,注释* text=auto这行即可.也可根据不同系统,做相应设定 ...

  5. 《AngularJS》--指令的相互调用

    转载自http://blog.csdn.net/zhoukun1008/article/details/51296692 人们喜欢AngularJS,因为他很有特色,其中他的指令和双向数据绑定很吸引着 ...

  6. Java多线程——ThreadLocal类

    一.概述   ThreadLocal是什么呢?其实ThreadLocal并非是一个线程的本地实现版本,它并不是一个Thread,而是threadlocalvariable(线程局部变量).也许把它命名 ...

  7. 简单竖向Tab选项卡

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. SQL语句添加删除修改字段及一些表与字段的基本操作

    用SQL语句添加删除修改字段 1.增加字段     alter table docdsp    add dspcode char(200)2.删除字段     ALTER TABLE table_NA ...

  9. Autofac 一个使用Demo

    一:接口 二:实现: 三:调用: 首先上图: 一:接口代码 public interface IPersonDa { PersonEntity Get(int id); } 二:实现 public c ...

  10. congos 日期控件的简单使用

    congos 添加html的标签,然后写上js的代码,这段代码的功能是得到前一天的日期. <input type="button" value="查询" ...