周末记录--2017.10.29

来源:互联网 发布:手机收发邮件软件 编辑:程序博客网 时间:2024/05/22 02:27

这两天看了看数位dp的题……然后忙活了一些别的事,复习考试,然后做了一场比赛。

数位dp的专题练习看了两道题,但是还没有做出来。然后后来看了那道可能比较简单的过的比较多的题,还没有过。

今晚上了那个专题看了看大佬已经做了9道题了。上次写博客的时候说就要开始做的,到现在还没有交。效率略低。

这次比赛出了两道题,也算是水题吧。然后第三道本来能出的,是一道模拟题,做了做最后交的时候卡在了第三十多组数据。然后心态就炸了……明明是一道模拟题,搞得这么麻烦……结果后来也没看出来是哪里错了……

Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.

Let A be a set of positions in the string. Let's call it pretty if following conditions are met:

  • letters on positions from A in the string are all distinct and lowercase; 
  • there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). 

Write a program that will determine the maximum number of elements in a pretty set of positions.

Input

The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.

The second line contains a string s consisting of lowercase and uppercase Latin letters.

Output

Print maximum number of elements in pretty set of positions for string s.

Example
Input
11aaaaBaabAbA
Output
2
Input
12zACaAbbaazzC
Output
3
Input
3ABC
Output
0
Note

In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.

In the second example desired positions can be 78 and 11. There are other ways to choose pretty set consisting of three elements.

In the third example the given string s does not contain any lowercase letters, so the answer is 0.



题目就是求大写字母之间不同的小写字母的种类的最大数目

#include <iostream>#include <cstring>#include <algorithm>#include <stdio.h>using namespace std;int main(){    int n;    while (scanf("%d",&n)!=EOF){        string a;        cin >> a;        int maxx = 0;        int flag[27];        memset(flag,0,sizeof(flag));        int flag2 = 0;        for (int i = 0; i < n; i++){            if (a[i] >= 'A' && a[i] <= 'Z'){                memset(flag,0,sizeof(flag));                flag2 = 0;            }            else{                if (flag[a[i]-'a'+1] == 0)                flag2++;                flag[a[i]-'a'+1]++;                if (maxx < flag2)                    maxx = flag2;            }        }        printf("%d\n",maxx);    }    return 0;}


Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.

Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.

The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.

Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair. 

Input

The first line contains a single integer n (2 ≤ n ≤ 100) — number of cards. It is guaranteed that n is an even number.

The following n lines contain a sequence of integers a1, a2, ..., an (one integer per line, 1 ≤ ai ≤ 100) — numbers written on the n cards.

Output

If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.

In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.

Example
Input
411272711
Output
YES11 27
Input
266
Output
NO
Input
6102030201020
Output
NO
Input
6112233
Output
NO
Note

In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2and 3. Thus, each of them will take exactly two cards.

In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.

In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.



这个题看了挺长时间的……就是按照游戏规则求啊……

#include <iostream>#include <cmath>#include <algorithm>#include <cstring>#include <stdio.h>#include <vector>using namespace std;int main(){    int n;    int a[100005];    while (scanf("%d",&n)!=EOF){        int c;        int flag = 0;        memset(a,0,sizeof(c));        vector <int> b;        for (int i = 1; i <= n; i++){            scanf("%d",&c);            if (a[c] == 0){                flag ++;                a[c]++;                b.push_back(c);            }            else                a[c]++;        }        if (flag != 2){            printf("NO\n");        }        else{            if (a[b[0]] != a[b[1]])                printf("NO\n");            else                printf("YES\n%d %d\n",b[0],b[1]);        }    }    return 0;}


数位dp的题还需要多看看多做做。还有些知识点理解的不够好。




原创粉丝点击