Berland National Library(模拟题目)


Berland National Library
Time Limit: 1000MSMemory Limit: 262144KB64bit IO Format: %I64d & %I64u
Submit
 
Status


Description
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.


Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:


"+ri" — the reader with registration number ri entered the room;
"-ri" — the reader with registration number ri left the room.
The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.


Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.


Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.


Input
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ri" or "-ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).


It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.


Output
Print a single integer — the minimum possible capacity of the reading room.


Sample Input
Input
6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7
Output
3
Input
2
- 1
- 2
Output
2
Input
2
+ 1
- 1
Output
1

一类模拟题,当初做的时候是在规定时间内做的,没有做完。思路也比较混乱,这个题目的意思是在一个房间中进去些人,出来些人,求出在里面的最大人数

 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;


int main()
{
    int a;
    int x[400];
    while (scanf("%d",&a)!=EOF)
    {
        getchar();
        int sum=1;
        int d;
        for (int number1=0;number1<a;number1++)
        {
            char y=getchar();
            getchar();
            if (y=='+')
            scanf("%d",&x[number1]);
            else
            {
                 scanf("%d",&d);
                x[number1]=-1*d;


            }
            getchar();
        }
        int flag,flag1;
        if (x[0]<0)
        {
            flag1=-1;
        }
        else
        {
            flag1=0;
        }
        int Max=0;
        for (int number1=1;number1<a;number1++)
        {
            for (int number2=number1-1;number2>=0;number2--)
            {
                if (x[number1]==x[number2]*(-1))
                {
                    if (x[number1]<0)
                    {
                        flag1-=1;
                    }
                    else if (x[number1]>0&&flag1>=0)
                    {
                        flag1=0;
                        sum+=1;
                    }
                    else if (x[number1]>0&&flag1<0)
                    {
                        flag1+=1;
                    }
                    break;
                }
                else  if (number2==0&&x[number1]>0&&flag1<0)
                {
                    flag1+=1;
                }
                else if (number2==0&&x[number1]>0&&flag1>=0)
                {
                    sum++;
                    flag1=0;
                }
                else if (number2==0&&x[number1]<0)
                {
                    sum++;
                    flag1-=1;
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}


 

posted @ 2016-02-24 17:13  十禾。  阅读(236)  评论(0编辑  收藏  举报