Vitaliy and Pie

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.

The potato pie is located in the n-th room and Vitaly needs to go there.

Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key.

In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.

Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.

Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.

Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number.

Input

The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house.

The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one.

The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2.

The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position iof the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1.

Output

Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n.

Sample Input

Input
3 aAbB
Output
0
Input
4 aBaCaB
Output
3
Input
5 xYyXzZaZ
Output
2
题解:注意钥匙只能用一次,刚开始ce,没敲头文件stdio....然后re,数组开小。。。然后wa,我傻逼的用位运算,这水题错了4次。。。
代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
const int MAXN = ;
char s[MAXN];
int key[];
int main(){
int N;
while(~scanf("%d", &N)){
int ky = , nu = ;
scanf("%s", s);
int len = strlen(s);
memset(key, , sizeof(key));
for(int i = ; i < len; i++){
if(s[i] >= 'A' && s[i] <= 'Z'){
if(key[s[i] - 'A'] > ){
key[s[i] - 'A']--;
}
else nu++;
}
else if(s[i] >= 'a' && s[i] <= 'z'){
key[s[i] - 'a']++;
}
}
printf("%d\n", nu);
}
return ;
}

Vitaliy and Pie(模拟)的更多相关文章

  1. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...

  2. Codeforces 525A - Vitaliy and Pie

    525A - Vitaliy and Pie 思路:贪心+hashing. 代码: #include<bits/stdc++.h> using namespace std; string ...

  3. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  4. cf- 297 < a >--字符串操作技巧

    A. Vitaliy and Pie time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. JS模拟Alert与Confirm对话框

    这2个例子都是用原生JS写的,主要是用JS拼接了界面,并未做过多的事件监听.,样式用了Css3的一些特性. 调用方式则为: //Alert Alert.show('我警告你哦~'); //Confir ...

  6. unity3d Human skin real time rendering 真实模拟人皮实时渲染(转)

    先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像 存在裂痕,解决方式是加入曲面细分和置换贴图 进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成 ...

  7. unity3d Human skin real time rendering plus 真实模拟人皮实时渲染 plus篇

    最近逃课做游戏,逃的有几门都要停考了,呵呵呵,百忙之中不忘超炒冷饭,感觉之前的人皮效果还是不够好,又改进了一些东西 首先上图 放大看细节 显而易见的比上次的效果要好很多,此次我把模型用3dmax进行了 ...

  8. unity3d Human skin real time rendering 真实模拟人皮实时渲染

    先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像存在裂痕,解决方式是加入曲面细分和置换贴图 进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成功 ...

  9. echart(2),模拟数据导入篇

    先上图,就是介样子的: 所模拟的效果就是讲左下角的li里面的数据取出来,然后用环形图的展示出数据. 看代码截图: 1.总的框架图: 2.循环取数据的js代码: 3.echart提供额官方api的代码 ...

随机推荐

  1. 一个sigaction的C++ wrap

    在上一篇文章(http://www.cnblogs.com/coding-my-life/p/4220128.html)中,提到了libev提供了处理信号的C++ wrap.但我显然接受不了需要进入l ...

  2. 详述.NET里class和struct的异同

    结构与类共享几乎所有相同的语法,但结构比类受到的限制更多:尽管结构的静态字段可以初始化,结构实例字段声明还是不能使用初始值设定项. 结构不能声明默认构造函数(没有参数的构造函数)或析构函数. 结构的副 ...

  3. PC--CSS技巧

    1.图片不存在的时候,显示一个默认图片 <img src=”01.jpg” onerror=”this.src=’02.jpg'” /> 2.CSS强制图片自适应大小 img {width ...

  4. Kafka在Linux环境下搭建过程

    准备工作 Kafka集群是把状态保存在Zookeeper中的,首先要搭建Zookeeper集群.由于我们之前的分布式系统中已经安装zookeeper服务,这里不进行zookeeper安装教程以及应用教 ...

  5. poj1562--Oil Deposits

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  6. 包含深度学习常用框架的Docker环境

    相关的代码都在Github上,请参见我的Github,https://github.com/lijingpeng/deep-learning-notes 敬请多多关注哈~~~ All in one d ...

  7. stm32之通用定时器TIM

    STM32系列的CPU,有多达8个定时器: 1.其中TMI1和TIM8是能够产生三对PWM互补输出的高级定时器,常用于三相电机的驱动:它们的时钟有APB2的输出产生: 2.其它6个为普通定时器,时钟由 ...

  8. .responsiveSlides参数

    $(".rslides").responsiveSlides({ auto: true, // Boolean: Animate automatically, true or fa ...

  9. JSP基础学习(一)

    1.jsp和servlet是javaEE规范的两个基本成员,是java web开发的重要知识,jsp和servlet本质上是一样的,因此jsp最终必须编译成servlet才能运行,或者说jsp是生成s ...

  10. respondsToSelector的相关使用

    -(BOOL) isKindOfClass: classObj 用来判断是否是某个类或其子类的实例 -(BOOL) isMemberOfClass: classObj 用来判断是否是某个类的实例 -( ...