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
3 aAbB
0
4 aBaCaB
3
5 xYyXzZaZ
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(模拟)的更多相关文章
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- Codeforces 525A - Vitaliy and Pie
525A - Vitaliy and Pie 思路:贪心+hashing. 代码: #include<bits/stdc++.h> using namespace std; string ...
- 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 ...
- cf- 297 < a >--字符串操作技巧
A. Vitaliy and Pie time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- JS模拟Alert与Confirm对话框
这2个例子都是用原生JS写的,主要是用JS拼接了界面,并未做过多的事件监听.,样式用了Css3的一些特性. 调用方式则为: //Alert Alert.show('我警告你哦~'); //Confir ...
- unity3d Human skin real time rendering 真实模拟人皮实时渲染(转)
先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像 存在裂痕,解决方式是加入曲面细分和置换贴图 进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成 ...
- unity3d Human skin real time rendering plus 真实模拟人皮实时渲染 plus篇
最近逃课做游戏,逃的有几门都要停考了,呵呵呵,百忙之中不忘超炒冷饭,感觉之前的人皮效果还是不够好,又改进了一些东西 首先上图 放大看细节 显而易见的比上次的效果要好很多,此次我把模型用3dmax进行了 ...
- unity3d Human skin real time rendering 真实模拟人皮实时渲染
先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像存在裂痕,解决方式是加入曲面细分和置换贴图 进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成功 ...
- echart(2),模拟数据导入篇
先上图,就是介样子的: 所模拟的效果就是讲左下角的li里面的数据取出来,然后用环形图的展示出数据. 看代码截图: 1.总的框架图: 2.循环取数据的js代码: 3.echart提供额官方api的代码 ...
随机推荐
- IOS 采用https 协议访问接口
申请好证书后,发现ios 仍无法使用https协议访问到数据,发现ios 需要ssl 支持 TLS1.2 . 更改nginx 配置: ssl_protocols TLSv1 TLSv1. TLSv1. ...
- 用JUnit4进行参数化测试
参数化测试是一个JUnit 3不具备的功能. 基本使用方法 @RunWith 当类被@RunWith注解修饰,或者类继承了一个被该注解修饰的类,JUnit将会使用这个注解所指明的运行器(runner) ...
- MyCat部署运行(Windows环境)与使用步骤详解
目录(?)[+] 1.MyCat概念 1.1 总体架构 MyCAT的架构如下图所示: MyCAT使用MySQL的通讯协议模拟成一个MySQL服务器,并建立了完整的Schema(数据库).Tab ...
- kaggle之泰坦尼克的沉没
Titanic 沉没 参见:https://github.com/lijingpeng/kaggle 这是一个分类任务,特征包含离散特征和连续特征,数据如下:Kaggle地址.目标是根据数据特征预测一 ...
- jquery插件datepicker
jQuery UI很强大,其中的日期选择插件Datepicker是一个配置灵活的插件,我们可以自定义其展示方式,包括日期格式.语言.限制选择日期范围.添加相关按钮以及其它导航等. <script ...
- ASP.NET MVC:自定义 Route 生成小写 Url(转)
先给出本文中测试用的 controller: public class PersonsController : Controller { public ActionResult Query(strin ...
- UIDeviceOrientation UIInterfaceOrientation 区别
UIDeviceOrientation 是机器硬件的当前旋转方向 这个你只能取值 不能设置 UIInterfaceOrientation 是你程序界面的当前旋转方向 这个可以设置 ...
- 使用正则表达式限制swing (JTextField等) 的输入
之前使用Qt编写Gui程序的时候,可以直接使用正则表达式限制所有输入框,非常方便. 这段时间要做一份课程设计,使用java编写,ui要限制输入,比如只能输入x位数字,输入身份证等. 百度了许多资料,发 ...
- (原+转)ubuntu14中结束多个caffe进程中的某个
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5948237.html 参考网址: http://www.2cto.com/os/201407/3215 ...
- Linux下VMWare虚拟机的使用技巧
使用技巧: 1.虚拟机安装文件:vm-workstation-full-8.0.3-703057.x86_64.bundle,./vm-workstation-full-8.0.3-703057.x8 ...