题意 Caisa走台阶 有n个台阶 第i个台阶的高度为h[i] 从第i个台阶包括地面到下一个台阶得到的能量为h[i]-h[i+1] 能量不足以跳到下一个台阶就要补充能量 求Caisa跳完所有台阶最少要补充多少能量

水题 直接模拟

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
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 100005;
int h[N];
int main()
{
int n, e, ans;
scanf("%d",&n);
for (int i = 1; i <= n; ++i)
scanf ("%d", &h[i]);
ans = 0;
for (int i = e = 0; i < n; ++i)
{
if (h[i] + e < h[i + 1])
{
int t = (h[i + 1] - e - h[i]);
h[i] += t;
ans += t;
}
e += (h[i] - h[i + 1]);
}
printf ("%d\n", ans);
return 0;
}

Caisa solved the problem with the sugar and now he is on the way back to home.

Caisa is playing a mobile game during his path. There are(n + 1)pylons numbered from0tonin this game. The pylon with number0has zero height, the pylon with numberi(i > 0)has heighth**i. The goal of the game is to reachn-th pylon, and the only move the player can do is to jump from the current pylon (let’s denote its number ask) to the next one (its number will bek + 1). When the player have made such a move, its energy increases byh**k - h**k + 1(if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.

Initially Caisa stand at0pylon and has0energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn’t want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Input

The first line contains integern(1 ≤ n ≤ 105). The next line containsnintegersh1,h2, …,h**n(1  ≤  h**i  ≤  105)representing the heights of the pylons.

Output

Print a single number representing the minimum number of dollars paid by Caisa.
Sample test(s)

input 5 3 4 3 2 4

output 4
input 3 4 4 4

output 4

Note

In the first sample he can pay4dollars and increase the height of pylon with number0by4units. Then he can safely pass to the last pylon.

Caisa去商店买Sugar 商店找零的最低单位为元 低于1元的部分每分找一个糖果 商店有n种Suger Caisa有s元钱 她只买一种Sugar 输入n s 再输入n行 每行两个数a b 表示第i种Sugar的单价为a元b分 求Sugar最多能被找多少糖果

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
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n, s, cos;
while (~scanf ("%d%d", &n, &s))
{
s *= 100;
int flag = 0, a, b, ans = 0;
while (n--)
{
scanf ("%d%d", &a, &b);
cos = a * 100 + b;
for (int j = 1; cos * j <= s; ++j)
{
flag = 1;
ans = max (ans, (s - cos) % 100);
}
}
printf ("%d\n", flag ? ans : -1);
}
return 0;
}

Caisais going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.

Unfortunately, he has justsdollars for sugar. But that’s not a reason to be sad, because there arentypes of sugar in the supermarket, maybe he able to buy one. But that’s not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn’t exceed99, because each seller maximizes the number of dollars in the change (100cents can be replaced with a dollar).

Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn’t want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Input

The first line contains two space-separated integersn, s(1 ≤ n, s ≤ 100).

Thei-th of the nextnlines contains two integersx**i,y**i(1 ≤ x**i ≤ 100; 0 ≤ y**i < 100), wherex**irepresents the number of dollars andy**ithe number of cents needed in order to buy thei-th type of sugar.

Output

Print a single integer representing the maximum number of sweetshe can buy, or-1if he can’t buy any type of sugar.
Sample test(s)

input 5 10 3 90 12 0 9 70 5 50 7 0

output 50
input 5 5 10 10 20 20 30 30 40 40 50 50

output -1

Note

In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take50sweets as a change.





题意 如果a加上a所有数位上的数等于b时 a称为b的generator 求给定数的最小generator

给的数n是小于100,000的 考虑到所有数位和最大的数99,999的数位和也才45 因此我们只需要从n-45到n枚举就行了

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
#include<cstdio>  
#include<cstring>
using namespace std;
int t, n, a, b, ans, l;
int main()
{
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
ans = 0;
for (int i = n-50; i < n; ++i)
{
a = b = i;
while (b)
{
a += b % 10;
b /= 10;
}
if (a + b == n)
{
ans = i;
break;
}
}
printf ("%d\n", ans);
}
return 0;
}

For a positive integer N , the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N , we call N a generator of M .

For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator of 256.

Not surprisingly, some numbers do not have any generators and some numbers have more than one generator. For example, the generators of 216 are 198 and 207.

You are to write a program to find the smallest generator of the given integer.

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case takes one line containing an integer N , 1$ \le$N$ \le$100, 000 .

Your program is to write to standard output. Print exactly one line for each test case. The line is to contain a generator of N for each test case. If N has multiple generators, print the smallest. If N does not have any generators, print 0.

The following shows sample input and output for three test cases.

3 216 121 2005

198 0 1979



题意 给一个字符串 判定其是否为回文串和镜像串 回文串很好判断 镜像串对于每一个字符用数组保存它的镜像字符就行了 没有的就是空格

注意若字符串长度为奇数 中间那个字母必须是对称的才是镜像串

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
#include<cstdio>
#include<cctype>
#include<cstring>
const int N = 35;
int l;
char s[N], mc[] = "A 3 HIL JM O 2TUVWXY5", mn[] = "1SE Z 8 ";

bool isRegular()
{
for (int i = 1; i <= l / 2; ++i)
if (s[i] != s[l - i + 1]) return false;
return true;
}

bool isMirrored()
{
for (int i = 1; i <= (l + 1) / 2 ; ++i)
{
if (isalpha (s[i]) && s[l - i + 1] != mc[s[i] - 'A']) return false;
else if (isdigit (s[i]) && s[l - i + 1] != mn[s[i] - '1']) return false;
}
return true;
}

int main()
{
while (scanf ("%s", s + 1) != EOF)
{
l = strlen (s + 1);
if (isMirrored())
{
if (isRegular()) printf ("%s -- is a mirrored palindrome.\n\n", s + 1);
else printf ("%s -- is a mirrored string.\n\n", s + 1);
}
else if (isRegular()) printf ("%s -- is a regular palindrome.\n\n", s + 1);
else printf ("%s -- is not a palindrome.\n\n", s + 1);
}
return 0;
}


A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string “ABCDEDCBA” is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left.

A mirrored string is a string for which when each of the elements of the string is changed to its reverse (if it has a reverse) and the string is read backwards the result is the same as the original string. For example, the string “3AIAE” is a mirrored string because “A” and “I” are their own reverses, and “3” and “E” are each others’ reverses.

A mirrored palindrome is a string that meets the criteria of a regular palindrome and the criteria of a mirrored string. The string “ATOYOTA” is a mirrored palindrome because if the string is read backwards, the string is the same as the original and because if each of the characters is replaced by its reverse and the result is read backwards, the result is the same as the original string. Of course, “A”, “T”, “O”, and “Y” are all their own reverses.

A list of all valid characters and their reverses is as follows.

Character Reverse Character Reverse Character Reverse A A M M Y Y B N Z 5 C O O 1 1 D P 2 S E 3 Q 3 E F R 4 G S 2 5 Z H H T T 6 I I U U 7 J L V V 8 8 K W W 9 L J X X

Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter “0” is a valid character.

Input consists of strings (one per line) each of which will consist of one to twenty valid characters. There will be no invalid characters in any of the strings. Your program should read to the end of file.

For each input string, you should print the string starting in column 1 immediately followed by exactly one of the following strings.

STRING CRITERIA “ – is not a palindrome.” if the string is not a palindrome and is not a mirrored string “ – is a regular palindrome.” if the string is a palindrome and is not a mirrored string “ – is a mirrored string.” if the string is not a palindrome and is a mirrored string “ – is a mirrored palindrome.” if the string is a palindrome and is a mirrored string

Note that the output line is to include the -‘s and spacing exactly as shown in the table above and demonstrated in the Sample Output below.

In addition, after each output line, you must print an empty line.

NOTAPALINDROME ISAPALINILAPASI 2A3MEAS ATOYOTA

NOTAPALINDROME – is not a palindrome. ISAPALINILAPASI – is a regular palindrome. 2A3MEAS – is a mirrored string. ATOYOTA – is a mirrored palindrome.

题意 求n以内等于两个连续素数的和加上1的数的个数 n不大于1000

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
#include<cstdio>  
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 1000;
int n, k, ans;
bool isPrime (int a)
{
for (int i = 2; i <= sqrt (a); ++i)
if (a % i == 0) return 0;
return 1;
}

int main()
{
int ai = 1, bi = 0, a[N], b[N];
a[1] = 2;
for (int i = 3; i <= N; ++i)
if (isPrime (i))
{
a[++ai] = i;
b[++bi] = a[ai] + a[ai - 1] + 1;
}
scanf ("%d%d", &n, &k);
ans = 0;
for (int i = 13; i <= n; ++i)
if (isPrime (i) && find (b + 1, b + bi + 1, i) != b + bi + 1)
ans++;
if (ans >= k) printf ("YES\n");
else printf ("NO\n");
return 0;
}

Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick’s attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least k prime numbers from 2 to n inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 =5 + 7 + 1.

Two prime numbers are called neighboring if there are no other prime numbers between them.

You are to help Nick, and find out if he is right or wrong.
Input

The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).

Output

Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.
Sample test(s)

input 27 2

output YES
input 45 7

output NO

Note

In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.



题意 一个窃贼到火柴仓库偷火柴 仓库有m个容器 第i个容器有a[i]个火柴盒 其中每个火柴盒中有b[i]根火柴 窃贼最大可以拿n个火柴盒 输入n m 然后m行a[i] b[i] 求窃贼最多能偷多少根火柴

很水的贪心 直接每次选当前火柴最多的盒子 n减去盒子数 直到n=0

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
#include<cstdio>  
#include<cstring>
#include<algorithm>
using namespace std;
const int M = 25;
int a[M], b[M], c[M], n, m, ans;

bool cmp (int i, int j)
{
return b[i] > b[j];
}

int main()
{
scanf ("%d%d", &n, &m);
for (int i = 1; i <= m; ++i)
{
c[i] = i;
scanf ("%d%d", &a[i], &b[i]);
}
sort (c + 1, c + m + 1, cmp);
ans = 0;
for (int i = 1; i <= m; ++i)
{
if (n >= a[c[i]])
{
n -= a[c[i]];
ans += a[c[i]] * b[c[i]];
}
else
{
ans += n * b[c[i]];
break;
}
}
printf ("%d\n", ans);
return 0;
}

A burglar got into a matches warehouseand wants to steal as many matches as possible. In the warehouse there are mcontainers, in the i-th container there are a**i matchboxes, and each matchbox contains b**i matches. All the matchboxes are of the same size. The burglar’s rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that’s why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal.
Input

The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers a**i and b**i (1 ≤ a**i ≤ 108, 1 ≤ b**i ≤ 10). All the input numbers are integer.

Output

Output the only number — answer to the problem.
Sample test(s)

input 7 3 5 10 2 5 3 6

output 62
input 3 3 1 3 2 2 3 1

output 7



题意 给你一些牌 全部正面朝下放桌子上 你选一个起点 翻开那张牌 牌上的数字是几就向前走几步 J,Q,K 都是向前走10步 A向前走11步 知道向前走对应的步数后超过了终点 输入n m 和n个数 代表你以第m张牌为起点 依次掀开了n张牌就不能再掀了 然后同样的牌 Alice以1-10张牌中的任意一个为起点 求Alice最后的终点与你的终点相同的概率

c[i]表示第i张牌的面值 没被掀开的牌的面值都是未知的c[i]=0 可能为2-A中的任意一个 令d[i]表示从你的终点到达第i张牌的概率 那么所有掀开过的牌的概率都为1 然后从终点向前递推 当p[i]=0时 p[i]=sum{p[i+j]} j为2-A中任意一张牌 注意10,j,q,k的时候都是10 最后的答案就是1到10的结果加起来除以10了

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
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1500;

int main()
{
char s[3];
int n, m, l;
double p[N], ans;
while (~scanf ("%d%d", &n, &m))
{
memset (p, 0, sizeof (p));
l = m;

for (int i = 1; i <= n; ++i)
{
scanf ("%s", s);
p[l] = 1;
if (s[0]<'A' && s[1]!='0') l += s[0] - '0';
else if (s[0] == 'A') l += 11;
else l+= 10;
}

ans = 0;
for (int i = l ; i >= 1; --i)
{
if (p[i] == 0)
{
for (int j = 2; j <= 11; ++j)
{
int t = (j == 10 ? 4 : 1);
p[i] += t * p[i + j];
}
p[i] /= 13;
}
if (i <= 10) ans += p[i];
}

printf ("%.8f\n", ans / 10);
}
return 0;
}

Card Trick

Time Limit: 2999/999MS (Java/Others) Memory Limit: 65432/65432KB (Java/Others)

Submit Status
I am learning magic tricks to impress my girlfriend Alice. My latest trick is a probabilistic one, i.e. it does work in most cases, but not in every case. To perform the trick, I first shuffle a set of many playing cards and put them all in one line with faces up on the table. Then Alice secretly selects one of the first ten cards (i.e. she choosesx0, a secret number between1and10inclusive) and skips cards repeatedly as follows: after having selected a card at positionxiwith a numberc(xi)on its face, she will select the card at positionxi+1=xi+c(xi). Jack (

1
J

), Queen (

1
Q

), and King (

1
K

) count as10, Ace (

1
A

) counts as11. You may assume that there are at least ten cards on the table.

Alice stops this procedure as soon as there is no card at positionxi+c(xi). I then perform the same procedure from a randomly selected starting position that may be different from the position selected by Alice. It turns out that often, I end up at the same position. Alice is very impressed by this trick.

However, I am more interested in the underlying math. Given my randomly selected starting position and the card faces of every selected card (including my final one), can you compute the probability that Alice chose a starting position ending up on the same final card? You may assume that her starting position is randomly chosen with uniform probability (between1and10inclusive). I forgot to note the cards that I skipped, so these cards are unknown. You may assume that the card face of every single of the unknown cards is independent of the other card faces and random with uniform probability out of the possible card faces (i.e.

1
2
1
10

,

1
J

,

1
Q

,

1
K

, and

1
A

).

title

*Illustration of first sample input: my starting position is2, so I start selecting that card. Then I keep skipping cards depending on the card’s face. This process iterates until there are not enough cards to skip (in this sample:

1
Q

). The final

1
Q

card is followed by0to9unknown cards, since

1
Q

counts as10.*

Input

For each test case:

Output

For each test case, print one line containing the probability that Alice chooses a starting position that leads to the same final card. Your output should have an absolute error of at most10−7.

Sample input and output

Sample Input Sample Output 5 2 2 3 5 3 Q 1 1 A 1 2 A 1 10 A 6 1 2 2 2 2 2 2 7 1 2 2 2 2 2 2 2 3 10 10 J K 0.4871377757023325348071573 0.1000000000000000000000000 0.1000000000000000000000000 0.1748923357025314239697490 0.5830713210321767445117468 0.6279229611115749556280350 0.3346565827603272001891974



题意 天坑开了个饭店 他知道所有客人的进来时间和出去的时间 求天坑至少准备多少张凳子

以分钟为单位 直接模拟就行了 peo[i]代表第i分钟的人 第i组人第si分钟进来 第so分钟出去 那么j从si到so peo[j]都加上这组的人数 最后看第几分钟人最多就是答案了

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
#include<cstdio>  
#include<cstring>
using namespace std;
const int N = 1441;
int hi, ho, mi, mo, si, so, t, n, ans, p, peo[N];


int main()
{
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
memset (peo, 0, sizeof (peo));
for (int i = 1; i <= n; ++i)
{
scanf ("%d %d:%d %d:%d", &p, &hi, &mi, &ho, &mo);
si = hi * 60 + mi;
so = ho * 60 + mo;
for (int j = si; j < so; ++j)
peo[j] += p;
}
for (int i = ans = 1; i < N; ++i)
if (peo[i] > ans) ans = peo[i];
printf ("%d\n", ans);
}
return 0;
}

TIANKENG’s restaurant

Problem Description

TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to have meal because of its delicious dishes. Today n groups of customers come to enjoy their meal, and there are Xi persons in the ith group in sum. Assuming that each customer can own only one chair. Now we know the arriving time STi and departure time EDi of each group. Could you help TIANKENG calculate the minimum chairs he needs to prepare so that every customer can take a seat when arriving the restaurant?
Input

The first line contains a positive integer T(T<=100), standing for T test cases in all. Each cases has a positive integer n(1<=n<=10000), which means n groups of customer. Then following n lines, each line there is a positive integer Xi(1<=Xi<=100), referring to the sum of the number of the ith group people, and the arriving time STi and departure time Edi(the time format is hh:mm, 0<=hh<24, 0<=mm<60), Given that the arriving time must be earlier than the departure time. Pay attention that when a group of people arrive at the restaurant as soon as a group of people leaves from the restaurant, then the arriving group can be arranged to take their seats if the seats are enough.
Output

For each test case, output the minimum number of chair that TIANKENG needs to prepare.
Sample Input

2 2 6 08:00 09:00 5 08:59 09:59 2 6 08:00 09:00 5 09:00 10:00
Sample Output

11 6





题意 有n个题目 完成第i个题目需要的时间为e[i] 第i个题目的系数为k[i] 你可以按任意顺序完成题目 比赛开始到完成第i个题目消耗的总时间为t[i] 那么完成第i个题目要扣掉k[i]/*t[i]分 求完成所有题目至少扣多少分

考虑任意相邻两题i,j 改变i,j时 i,j之前和之后所有的题目对结果都没有影响 只是i,j两题的扣分和由原来的(t+e[i])/*k[i]+(t+e[i]+e[j])/*k[j]变成了(t+e[i]+e[j])/*k[i]+(t+e[j])/*k[j]
比较可以发现只是e[i]/*k[j]变成了e[j]/*k[i] 所以 若e[i]/*k[j]<e[j]/*k[i] 那么i就应该在j之前完成 以此进行排序即可

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
<span style="font-size:14px;">#include<cstdio>  
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100050;
ll k[N], o[N], t[N], e[N], n;

bool cmp (int i, int j)
{
return (e[i] * k[j] < e[j] * k[i]);
}

int main()
{
while (scanf ("%I64d", &n) != EOF)
{
for (int i = 1; i <= n; ++i)
scanf ("%I64d", &e[i]);

for (int i = 1; i <= n; ++i)
{
o[i] = i;
scanf ("%I64d", &k[i]);
}
sort (o + 1, o + n + 1, cmp);
ll ans=0;

for (int i = 1; i <= n; ++i)
{
int j=o[i];
t[j]=t[o[i-1]]+e[j];
ans += k[j] * t[j];
}
printf ("%I64d\n", ans);
}
return 0;
} </span>

Though ZCC has many Fans, ZCC himself is a crazy Fan of a coder, called “Memset137”.
It was on Codefires(CF), an online competitive programming site, that ZCC knew Memset137, and immediately became his fan.
But why?
Because Memset137 can solve all problem in rounds, without unsuccessful submissions; his estimation of time to solve certain problem is so accurate, that he can surely get an Accepted the second he has predicted. He soon became IGM, the best title of Codefires. Besides, he is famous for his coding speed and the achievement in the field of Data Structures.
After become IGM, Memset137 has a new goal: He wants his score in CF rounds to be as large as possible.
What is score? In Codefires, every problem has 2 attributes, let’s call them Ki and Bi(Ki, Bi>0). if Memset137 solves the problem at Ti-th second, he gained Bi-Ki/*Ti score. It’s guaranteed Bi-Ki/*Ti is always positive during the round time.
Now that Memset137 can solve every problem, in this problem, Bi is of no concern. Please write a program to calculate the minimal score he will lose.(that is, the sum of Ki/*Ti).
Input

The first line contains an integer N(1≤N≤10^5), the number of problem in the round.
The second line contains N integers Ei(1≤Ei≤10^4), the time(second) to solve the i-th problem.
The last line contains N integers Ki(1≤Ki≤10^4), as was described.
Output

One integer L, the minimal score he will lose.
Sample Input

3 10 10 20 1 2 3
Sample Output

150



题意 给你一个长度为12的字符串 由字符’-‘和字符’o’组成 其中”-oo”和”oo-“分别可以通过一次转换变为”o–”和”–o” 可以发现每次转换o都少了一个 只需求出给你的字符串做多能转换多少次就行了

令d[s]表示字符串s最多可以转换的次数 若s可以通过一次转换变为字符串t 有d[s]=max(d[s],d[t]+1)

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
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string, int> d;
int n, ans;
string t, S;

int dp (string s)
{
if (d[s] > 0) return d[s];
d[s] = 1;
for (int i = 0; i < 10; ++i)
{
if (s[i] == 'o' && s[i + 1] == 'o' && s[i + 2] == '-')
{
t = s;
t[i] = t[i + 1] = '-';
t[i + 2] = 'o';
d[s] = max (d[s], dp (t) + 1);
}
if (s[i] == '-' && s[i + 1] == 'o' && s[i + 2] == 'o')
{
t = s;
t[i] = 'o';
t[i + 1] = t[i + 2] = '-';
d[s] = max (d[s], dp (t) + 1);
}
}
return d[s];
}

int main()
{
cin >> n;
while (n--)
{
ans = 1;
cin >> S;
for (int i = 0; i < 12; ++i)
if (S[i] == 'o') ans++;
ans -= dp (S);
cout << ans << endl;
}
return 0;
}

Pebble Solitaire

Pebble solitaire is an interesting game. This is a game where you are given a board with an arrangement of small cavities, initially all but one occupied by a pebble each. The aim of the game is to remove as many pebbles as possible from the board. Pebbles disappear from the board as a result of a move. A move is possible if there is a straight line of three adjacent cavities, let us call themA,B, andC, withBin the middle, whereAis vacant, butBandCeach contain a pebble. The move constitutes of moving the pebble fromCtoA, and removing the pebble inBfrom the board. You may continue to make moves until no more moves are possible.

In this problem, we look at a simple variant of this game, namely a board with twelve cavities located along a line. In the beginning of each game, some of the cavities are occupied by pebbles. Your mission is to find a sequence of moves such that as few pebbles as possible are left on the board.

Input

The input begins with a positive integernon a line of its own. Thereafterndifferent games follow. Each game consists of one line of input with exactly twelve characters, describing the twelve cavities of the board in order. Each character is either**’-‘or‘o’(The fifteenth character of English alphabet in lowercase). A‘-‘(minus) character denotes an empty cavity, whereas a‘o’**character denotes a cavity with a pebble in it. As you will find in the sample that there may be inputs where no moves is possible.

Output

For each of the n games in the input, output the minimum number of pebbles left on the board possible to obtain as a result of moves, on a row of its own.

Sample InputOutput for Sample Input

5

—oo——-

-o–o-oo—-

-o—-ooo—

oooooooooooo

oooooooooo-o

1

2

3

12

1


0%