模拟 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 const int INF = 0x3f3f3f3f;
14 int cnt[33];
15 char s[MAXN];
16
17 int main(void)        //Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
18 {
19     int n;
20     while (scanf ("%d", &n) == 1)
21     {
22         scanf ("%s", s);    int len = strlen (s);
23         memset (cnt, 0, sizeof (cnt));
24
25         int ans = 0;
26         for (int i=1; i<len; i+=2)
27         {
28             cnt[s[i-1]-‘a‘]++;
29             if (cnt[s[i]-‘A‘])    cnt[s[i]-‘A‘]--;
30             else    ans++;
31         }
32
33         printf ("%d\n", ans);
34     }
35
36     return 0;
37 }
38
39
40 /*
41 3
42 aAbB
43 4
44 aBaCaB
45 5
46 xYyXzZaZ
47 */
时间: 2024-12-22 07:52:22

模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie的相关文章

BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls

题目传送门 1 /* 2 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 3 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 4 在2*2的方格里,若只有一个是'*',那么它一定要被替换掉 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 #include <queue> 1

贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

题目传送门 1 /* 2 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 3 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 typedef long long ll; 12 13 co

queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

题目传送门 1 /* 2 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 3 queue容器:模拟上述过程,当次数达到最大值时判断为-1 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 #include <string> 10 #include <stack> 11 #in

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

Codeforces Round #297 (Div. 2)(模拟+字符串+排序)

A. 题目链接:点击打开链接 解题思路: 大意就是说奇数位给小写字母,偶数位给大写字母,然后小写对应钥匙,大写对应门,问最少消耗几把钥匙能打开所有门. 简单模拟即可,初始化一个英文字母数组,如果遇到小写字母,我们把相应的计数器++,遇到大写,如果它对应的数组值不为0,那么我们将其--, 否则购买一把钥匙. 完整代码: #include <iostream> #include <cstdio> #include <algorithm> #include <cstri

Codeforces Round #297 (Div. 2)E. Anya and Cubes

题目链接:http://codeforces.com/problemset/problem/525/E 题意: 给定n个数,k个感叹号,常数S 下面给出这n个数. 目标: 任意给其中一些数变成阶乘,至多变k个. 再任意取一些数,使得这些数和恰好为S 问有多少方法. 思路: 三进制状压,0代表不取,1代表取阶乘,2代表直接取: 中途查找,节约空间: 代码如下: #include<cstdio> #include<cstring> #include<iostream> #i

Codeforces Round #297 (Div. 2)B Pasha and String

B. Pasha and String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the

Codeforces Round #297 (Div. 2)

A题 题目大意: 给你一个字符串,奇数的时候是钥匙,偶数的时候是门,一把钥匙只能开对应的门,然后问你最少额外需要多少把钥匙. 分析: 用的数组记录一下就行,(注意的是先开门,再拿钥匙!开始错在这里了,决心好好学英语) #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<queue> #inc

Codeforces Round #297 (Div. 2) E题. Anya and Cubes (中途相遇法)

题目地址:Anya and Cubes 比赛的时候居然没想起中途相遇法...这题也是属于想起来就很简单系列. 中途相遇法也叫折半搜索.就是处理前一半,把结果储存起来,再处理后一半,然后匹配前一半存储的结果. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib