【HDOJ】1497 Simple Library Management System
链表。
#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的更多相关文章
- Simple Library Management System HDU - 1497(图书管理系统)
Problem Description After AC all the hardest problems in the world , the ACboy 8006 now has nothing ...
- 【HDOJ】2451 Simple Addition Expression
递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41- ...
- 【HDOJ】1341 Simple Computers
注意PC要与31. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 40 ...
- 【CF802C】Heidi and Library(网络流)
[CF802C]Heidi and Library(网络流) 题面 CF 洛谷 题解 前面两个Easy和Medium都是什么鬼玩意啊.... 不难发现如果这天的要求就是第\(a_i\)种书的话,那么\ ...
- 【BZOJ3489】A simple rmq problem(KD-Tree)
[BZOJ3489]A simple rmq problem(KD-Tree) 题面 BZOJ 题解 直接做肯定不好做,首先我们知道我们是一个二维平面数点,但是限制区间只能出现一次很不好办,那么我们给 ...
- 【CF802C】Heidi and Library (hard) 费用流
[CF802C]Heidi and Library (hard) 题意:有n个人依次来借书,第i人来的时候要求书店里必须有种类为ai的书,种类为i的书要花费ci块钱购入.而书店的容量只有k,多余的书只 ...
- 【BZOJ3489】A simple rmq problem
[BZOJ3489]A simple rmq problem 题面 bzoj 题解 这个题不强制在线的话随便做啊... 考虑强制在线时怎么搞 预处理出一个位置上一个出现的相同数的位置\(pre\)与下 ...
- 【BZOJ3489】A simple rmq problem kd-tree
[BZOJ3489]A simple rmq problem Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过 ...
- 【Winform】 无法将类型为“System.Windows.Forms.SplitContainer”的对象强制转换为类型“System.ComponentModel.ISupportInitialize”。
问题:将dotnet framework 4.0 切换到2.0时,编译没有问题,在运行时出现如下错误:System.InvalidCastException: 无法将类型为“System.Window ...
随机推荐
- windows 编程 —— 消息与参数(滚动条、键盘、鼠标)
目录: 滚动条 键盘 鼠标 滚动条ScrollBar 发送消息:WM_VSCROLL和WM_HSCROLL 参数wParam:wParam消息参数被分为一个低字组和一个高字组.wParam的低字组是一 ...
- ionic上拉加载更多解决方法
第一步: $scope.hasmore = true;//是否允许上拉加载 $scope.num = 8;//显示条数 第二步://查询显示内容,查出所有的 $scope.Group = functi ...
- Html5新特性 <canvas>画板画直线
以下样例为用canvas标签画多条直线 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...
- Android开发系列(十八):自己定义控件样式在drawable目录下的XML实现
在Android开发的过程中,我们常常须要对控件的样式做一下改变,能够通过用添加背景图片的方式进行改变,可是背景图片放多了肯定会使得APK文件变的非常大. 我们能够用自己定义属性shape来实现. s ...
- 大数据笔记03:大数据之Hadoop的安装
1.安装Hadoop (1)准备Linux环境 (2)安装JDK (3)配置Hadoop 2.准备Linux环境 (1)我们用户可能都是使用Windows环境,一般用户都是先安装虚拟机,然后在虚拟机上 ...
- GSON 示例代码 实用版
去除所有格式的json字符串 {"data":[{"friend":[{"address":"广州","nam ...
- spring源码分析构建
命令如下: ant ant install-maven ant jar package E:\download\spring-framework-3.1.3.RELEASE\build-spring- ...
- Windows7电脑上不去网,ipconfig查询时默认网关会出现0.0.0.0问题的解决
用ipconfig查看网络配置,发现其他都正确,唯独默认网关上多了一条0.0.0.0的记录,.禁用网络连接再启用也不能恢复.网上找了一下有说改注册表的,打开注册表找到 HKEY_LOCAL_MACHI ...
- The account '' has no team with ID ''
Xcode 升级到7.2 版本,真机测试的时候报错:The account '' has no team with ID '' 解决办法1:http://stackoverflow.com/quest ...
- Swift - 40 - 枚举更加灵活的使用方式
//: Playground - noun: a place where people can play import UIKit /* 这里的枚举没有给它的成员默认值, 而是给它绑定了一个类型, 之 ...