Vitaliy and Pie(模拟)

Vitaliy and Pie

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

Submit Status Practice CodeForces 525A

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 = 500010;
char s[MAXN];
int key[30];
int main(){
    int N;
    while(~scanf("%d", &N)){
        int ky = 0, nu = 0;
        scanf("%s", s);
        int len  = strlen(s);
        memset(key, 0, sizeof(key));
        for(int i = 0; i < len; i++){
            if(s[i] >= ‘A‘ && s[i] <= ‘Z‘){
                if(key[s[i] - ‘A‘] > 0){
                    key[s[i] - ‘A‘]--;
                }
                else nu++;
            }
            else if(s[i] >= ‘a‘ && s[i] <= ‘z‘){
                key[s[i] - ‘a‘]++;
            }
        }
        printf("%d\n", nu);
    }
    return 0;
}
时间: 2024-11-18 14:57:49

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

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

题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 using namespace std; 11 12 const int MAXN = 2e5 + 10; 13

Codeforces Round #297 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/525 算是比较简单的一场了,拖了好久现在才补 A. Vitaliy and Pie time limit per test:2 seconds memory limit per test:256 megabytes After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that sim

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

最近逃课做游戏,逃的有几门都要停考了,呵呵呵,百忙之中不忘超炒冷饭,感觉之前的人皮效果还是不够好,又改进了一些东西 首先上图 放大看细节 显而易见的比上次的效果要好很多,此次我把模型用3dmax进行了细化,模型裂缝情况有所好转,但是嘴唇等处还是有明显裂缝(没办法,网上没有比这个再细致的贴图了) 去除了之前所有大量的rim,换成了SSS次表面散射之前一篇文章详细讲过, SSS次表面散射的参数真心难调= =: 漫反射换成了基于物理的Oren Nayar反射模型 specular 高光反射与之前一篇相

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

先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像 存在裂痕,解决方式是加入曲面细分和置换贴图 进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成功了但是着色效果变的很奇怪,这里就不用曲面细分了,大家如果有在fragment shader上用曲面细分的好办法,可以的话请告诉我 参数设置1 参数设置2 细致到毛孔的高光 次表面散射的耳朵 人皮渲染是十多年的课题了,人们想尽一切办法想让其变得真实可信,大型3A级次时代游戏近来做的又来越真实了如<罗

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

先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像存在裂痕,解决方式是加入曲面细分和置换贴图进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成功了但是着色效果变的很奇怪,这里就不用曲面细分了,大家如果有在fragment shader上用曲面细分的好办法,可以的话请告诉我 参数设置1 参数设置2 细致到毛孔的高光 次表面散射的耳朵 人皮渲染是十多年的课题了,人们想尽一切办法想让其变得真实可信,大型3A级次时代游戏近来做的又来越真实了如<罗马之

POJ 3311 Hie with the Pie(状压dp or dfs)

Language: Default Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5057   Accepted: 2695 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutba

Python使用FaKer模拟数据!!!

hello,小伙伴们,大家好,今天给大家介绍的开源项目是: Faker,它解决的问题是python模拟(随机)数据!不知道大家在工作中没有用到过假数据,特别前后端开发的人员,应该经常用到,前端人员页面展示,效果展示.后端人员数据库数据模拟.今天给大家介绍的这个项目完美的解决了这个方案,可以模拟多种语言的数据,中文,英文,日语,韩语等等.有兴趣的小伙伴可以下载尝试一下. _|_|_|_| _| _| _|_|_| _| _| _|_| _| _|_| _|_|_| _| _| _|_| _|_|_

CentOS系统启动及内核大破坏模拟实验

讲过了centos的启动流程,此时是不是想来点破坏呢?那就尽情的玩耍吧,记得在实验之前拍个快照,万一哪个环节错误恢复不回来了呢,毕竟数据无价,话不多说,开始. 一.删除伪系统根.(ramdisk文件) (1)模拟误操作删除ramdisk文件. ①模拟误删除initramfs-3.10.0-514.el7.x86_64.img文件. ②为当前正在使用的内核重新制作ramdisk文件 格式为:mkinitrd /boot/initramfs-$(uname -r).img $(uname -r) (

NYOJ 2356: 哈希计划【模拟】

题目描述 众所周知,LLM的算法之所以菜,就是因为成天打游戏,最近LLM突然想玩<金庸群侠传X>,结果进去后各种被虐,LLM就开始研究这个游戏的代码,顺便还学会了一点点点点lua语言,然后就开始了伟大的改游戏代码之旅,然后LLM发现自己too young了,这个游戏把所有的文本都进行了哈希,如果自己改了代码或者剧情文本的话它哈希出来的值就会和原来的哈希值不一样......然后游戏就会打不开.....,现在LLM发现了文本的哈希函数,要求你写个程序,功能为: 输入一段字符串,输出一个哈希值 为了