这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可

 #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的更多相关文章

  1. CodeForces 567B Berland National Library

    Description Berland National Library has recently been built in the capital of Berland. In addition, ...

  2. Codeforces B - Berland National Library

    B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. HDU 5477 A Sweet Journey 水题

    A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  4. HDU 5477: A Sweet Journey

    A Sweet Journey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. Codeforces 567B:Berland National Library(模拟)

    time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...

  6. 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 ...

  7. Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟

    B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  8. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  9. Codeforces Round #Pi (Div. 2) B Berland National Library

    B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...

随机推荐

  1. java 导出excel(简单案例)

    public class Student { private int id; private String name; private int age; private Date birth; pub ...

  2. hdu_5908_Abelian Period(暴力)

    题目链接:hdu_5908_Abelian Period 题意: 给你n个数字,让你找出所有的k,使得把这n个数字分为k分,并且每份的数字种类和个数必须相同 题解: 枚举k,首先k必须是n的约数,然后 ...

  3. Mysql字符集修改为UTF8

    修改/etc/my.cnf,这个文件是安装的时候拷贝过去的 修改方法: [client]下添加 default-character-set=utf8 [mysqld]下添加 character-set ...

  4. Django中使用ModelForm实现Admin功能

    接上一篇<Django中使用Bootstrap> ModelForm 可以将数据库中的信息展示在一个表中,因此我们在查询数据库信息时可以使用ModelForm在前端展示查询到的信息. 在上 ...

  5. ubuntu 调试库

    .安装带有调试信息的libc: sudo apt-get install libc6-dbg .下载libc源码 a.选定一个放置源码的目录并进入,如 /home/kent/dev-os/libc6- ...

  6. HDU 2216 Game III(BFS)

    Game III Problem Description Zjt and Sara will take part in a game, named Game III. Zjt and Sara wil ...

  7. Gentoo/Funtoo USE标记介绍

    Gentoo/Funtoo USE标记 USE的简单理解如下:一个软件不只包含软件本身,还包括其组件,如,文档,插件,GUI支持等.USE就是用来标记是否要安装软件的同时安装这些组件. 声明USE标记 ...

  8. UI----安健2 UIswitch UIslider

    - (void)viewDidLoad { [super viewDidLoad]; [self buttonswitch]; [self buttonslider]; } -(void)button ...

  9. The server instance Witness rejected configure request; read its error log file for more information. The reason 1427, and state 31, can be of use for

    数据库服务器做了镜像之后,发现有错误信息 The server instance Witness rejected configure request; read its error log file ...

  10. Neutron 不健全的HA ROUTER

    首先介绍下HA,所谓的HA就是高可用性,但HA有双主.主备两种工作模式,其中主备模式又包含抢占与 非抢占两种方式,而Neutron Router采用的无疑是HA中最简单的工作方式非抢占主备模式. HA ...