A 2Char
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.
Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.
Input
The first line of the input contains number n (1 ≤ n ≤ 100) — the number of words in the article chosen by Andrew. Following are n lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.
Output
Print a single integer — the maximum possible total length of words in Andrew's article.
Sample test(s)
input
4
abb
cacc
aaa
bbb
output
9
input
5
a
a
bcbcb
cdecdecdecdecdecde
aaaa
output
6
Note
In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.
题目类型:暴力枚举
算法分析:先预处理出每个字符串的字符种数和个数,然后双重循环枚举两个字符,并更新最大值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
#pragma comment(linker, "/STACK:102400000,102400000") #include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("aaa.txt", "r", stdin) #define CPPFF ifstream cin ("aaa.txt") #define DB(ccc) cout << #ccc << " = " << ccc << endl #define PB push_back #define MP(A, B) make_pair(A, B) typedef long long LL; typedef unsigned long long ULL; typedef double DB; typedef pair <int, int> PII; typedef pair <int, bool> PIB; const int INF = 0x7FFFFFFF; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 1e6 + 66; int cnt[1666][36]; int main() { // CPPFF; int n; cin >> n; memset (cnt, 0, sizeof (cnt)); string s; for (int i = 0; i < n; i++) { cin >> s; for (int j = 0; j < s.size (); j++) cnt[i][s[j]-'a']++; } LL maxval = -INF; for (int i = 0; i < 26; i++) { LL temp; for (int j = i + 1; j < 26; j++) { temp = 0; for (int k = 0; k < n; k++) { bool is_valid = true; for (int q = 0; q < 26; q++) { if (q != i && q != j && cnt[k][q]) { is_valid = false; break; } } if (is_valid) temp += (cnt[k][i] + cnt[k][j]); } maxval = max (maxval, temp); } } cout << maxval << endl; return 0; } |
B Anton and Lines
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x1 < x2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that:
- y' = ki * x' + bi, that is, point (x', y')belongs to the line number i;
- y' = kj * x' + bj, that is, point (x', y')belongs to the line number j;
- x1 < x' < x2, that is, point (x', y')lies inside the strip bounded by x1 < x2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
Input
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers ki, bi ( - 1 000 000 ≤ ki, bi ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either ki ≠ kj, or bi ≠ bj.
Output
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
Sample test(s)
input
4
1 2
1 2
1 0
0 1
0 2
output
NO
input
2
1 3
1 0
-1 3
output
YES
input
2
1 3
1 0
0 2
output
YES
input
2
1 3
1 0
0 3
output
NO
Note
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
题目类型:简单几何
算法分析:计算出所有的直线在x1+EPS和x2-EPS处的值y1和y2,然后分别对两个位置处的函数值排序,若两端的y值从小到大都属于同一个直线的话,则说明没有直线相交,否则有直线相交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
#pragma comment(linker, "/STACK:102400000,102400000") #include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("aaa.txt", "r", stdin) #define CPPFF ifstream cin ("aaa.txt") #define DB(ccc) cout << #ccc << " = " << ccc << endl #define PB push_back #define MP(A, B) make_pair(A, B) typedef long long LL; typedef unsigned long long ULL; typedef double DB; typedef pair <int, int> PII; typedef pair <int, bool> PIB; const int INF = 0x7FFFFFFF; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 1e5 + 6666; struct node { double v; int id; }; bool operator < (const node&a, const node&b) {return a.v < b.v;} node aa[maxn], bb[maxn]; int main() { // CFF; int n; scanf ("%d", &n); int x1, x2; scanf ("%d %d", &x1, &x2); for (int i = 1; i <= n; i++) { int ki, bi; scanf ("%d %d", &ki, &bi); aa[i].v = ki * 1.0 * (x1 + EPS) + bi; aa[i].id = i; bb[i].v = ki * 1.0 * (x2 - EPS) + bi; bb[i].id = i; } sort (aa + 1, aa + 1 + n); sort (bb + 1, bb + 1 + n); bool is_find = false; for (int i = 1; i <= n; i++) { if (aa[i].id != bb[i].id) { is_find = true; break; } } if (is_find) puts ("YES"); else puts ("NO"); return 0; } |
- « 上一篇:poj3279
- hdu1257:下一篇 »