链表。

 #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. angularjs于directive声明scope说明何时以及如何使用对象修饰符

    于angular我们定义directive方法.查看 return { restrict: 'AE', scope: {}, template: '<div></div>', ...

  2. TinyXml高速入门(一)

    作者:朱金灿 来源:http://blog.csdn.net/clever101 对于xml文件,眼下我的工作仅仅是集中在配置文件和作为简单的信息文件来用,因此我不太喜欢使用msxml这样的重量级的x ...

  3. android-继承BaseAdapter--自定义适配器,getView执行多次的解决方法

    定义的getView执行多次的ListView布局: <ListView android:id="@+id/lv_messages" android:layout_width ...

  4. 复杂 Listview 显示 多个样式

    三种方式 目前为止有三种方法让Listview现实多个样式 最简单最常用的,通过addHeaderView或addFooterView,但是只能在首尾添加 较麻烦但正规的方式,通过getViewTyp ...

  5. mysql02

    -- 查询课程名称 和年级的名称 -- 非等值连接查询 SELECT subjectname,gradeName FROM `subject`,grade -- 等值连接查询 SELECT subje ...

  6. 菜鸟学习Ado.net笔记一:Ado.net学习之SqlHelper类

    using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; usin ...

  7. hdu 1728

    //hdu 1728 //这个是一道很经典的迷宫题了,思路感觉...取起点和终点,判断连线是否超过n个弯, //先是从起点出发,上下左右四个方向搜索,找到一条路,把那条路的第一个点压入队列 //然后沿 ...

  8. ImageIO.wtrie生成jpg图片质量损失方案:BufferedImage生成jpg图片文件流

    Iterator<ImageWriter> iterator = ImageIO.getImageWritersByFormatName("jpeg"); ImageW ...

  9. 设为首页 收藏(IE可用)

    function SetHome(obj, vrl) { try { obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vr ...

  10. 如何在github上传自己的项目

    1.首先在github创建自己的账号. 2.下载github for windows 客户端 (备注:这里我的电脑是windows系统的) ,不要下载错了,网上下载的应该是这样的安装程序 3.安装gi ...