CodeForces 567B Berland National Library hdu-5477 A Sweet Journey
这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可
#include<cstdio>
#include<cstring> const int HASH=; int n,num[],head[HASH],next[]; void insert(int s)
{
int h=num[s]%HASH;
int u=head[h];
while(u) u=next[u];
next[s]=head[h];//原来的链表头成为s的next
head[h]=s;//s成为head[h]的链表头
} int erase(int s)
{
int h=num[s]%HASH;
int u=head[h];
while(u)
{
if(num[u]==num[s])
{
num[u]=;
return ;
}
u=next[u];
}
return ;
} int main()
{
while(scanf("%d",&n)==)
{
int x,cap=,j=,maxcap=;
char op[];
memset(head,,sizeof(head));
for(int i=;i<=n;i++)
{
scanf("%s%d",op,&num[j]);
if(op[]=='+')
{
insert(j);
j++;
cap++;
//printf("cap=%d\n",cap);
if(cap>maxcap) maxcap=cap;
}
else
{
if(erase(j)) cap--;
else maxcap++;//在记下maxcap之前已经在里面
//printf("cap=%d\n",cap);
if(cap>maxcap) maxcap=cap;
}
}
printf("%d\n",maxcap);
}
return ;
}
#include<cstdio>
#include<cstring> int T,n,a,b,L,cas=; int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&n,&a,&b,&L);
int l,r,strength=,min=,last=;
for(int i=;i<n;i++)
{
scanf("%d%d",&l,&r);
strength+=b*(l-last)-a*(r-l);
if(strength<min) min=strength;
last=r;
}
printf("Case #%d: %d\n",cas++,-min);
}
return ;
}
CodeForces 567B Berland National Library hdu-5477 A Sweet Journey的更多相关文章
- CodeForces 567B Berland National Library
Description Berland National Library has recently been built in the capital of Berland. In addition, ...
- Codeforces B - Berland National Library
B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...
- HDU 5477 A Sweet Journey 水题
A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 5477: A Sweet Journey
A Sweet Journey Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Codeforces 567B:Berland National Library(模拟)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- Codeforces Round #Pi (Div. 2) B. Berland National Library set
B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟
B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- Codeforces Round #Pi (Div. 2) B Berland National Library
B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...
随机推荐
- php基础(六)Include
本文内容来自http://www.w3school.com.cn/php/php_file.asp 服务器端包含 (SSI) 用于创建可在多个页面重复使用的函数.页眉.页脚或元素. include ( ...
- JavaScript原生对象总纲
一. javascript之Array类 创建js数组两种方式: var arr = []; 或var arr = new Array(); ()里可以指定长度,也可以不指定,指不指定都无所谓,因为 ...
- lua 中操作系统库
time 和 date 两个函数在lua中实现所有的时钟查询功能. 函数time在没有参数时返回当前时钟的数值.(在许多操作系统中,该数值是距离某个特定时间的秒数). date是time的一种“反函数 ...
- HDU 1242 Rescue(BFS),ZOJ 1649
题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...
- [转]详细的mysql时间和日期函数
这里是一个使用日期函数的例子.下面的查询选择了所有记录,其date_col的值是在最后30天以内: mysql> SELECT something FROM table WHERE TO_DAY ...
- 图片拉伸:resizableImageWithCapInsets
iOS 5.0 在iOS 5.0中,UIImage有一个新方法可以处理图片的拉伸问题 - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)ca ...
- 用mybatis生成插件自动生成配置文件
1.在当前的maven项目的pom.xml中添加插件 <build> <plugins> <plugin> <groupId>org.mybatis.g ...
- ecos 问题答疑(转)
1.为什么我购买的是源码版,但是我的base/ego.php(或者base/ego/目录下文件)却是加密的? 答:ego 源码商业授权文件仅用于和商派软件签订源码协议的商业用户按照甲乙的源码保护约定 ...
- Linux系统安装建议
1.推荐使用CentOS-6.x 64位版本:2.分区,推荐分出/usr/local用来存放应用程序./data分区用来存放数据,具体分区建议如下:/boot 100Mswap 4096M (视内存大 ...
- c题 Registration system
Description A new e-mail service "Berlandesk" is going to be opened in Berland in the near ...