Codeforces Beta Round #12

A - Super Agent

There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.

Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3 × 3 with digits from 1 to 9.

Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.

Input

Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».

Output

Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.

Examples

Input

XX.
...
.XX

Output

YES

Input

X.X
X..
...

Output

NO

Note

If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry

判断给出的矩阵是否中心对称

#include <cstdio>
#include <iostream>
using namespace std;

char m[5][5];

int main(void)
{
	bool flag = 1;
	for (int i = 0; i < 3; i++)
		cin >> m[i];
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
		{
			if (m[i][j] != m[2 - i][2 - j])
				flag = 0;
		}
	if (flag)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

B - Correct Solution?

One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice’s turn, she told the number n to Bob and said:

—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.

—No problem! — said Bob and immediately gave her an answer.

Alice said a random number, so she doesn’t know whether Bob’s answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.

Input

The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob’s answer, possibly with leading zeroes.

Output

Print OK if Bob’s answer is correct and WRONG_ANSWER otherwise.

Examples

Input

3310
1033

Output

OK

Input

4
5

Output

WRONG_ANSWER

这道题先对数组进行排序,如果含有0,就将第一个0与第一个非0数交换。
坑点在于,如果输入的只是0,那么就会把‘0’与‘\0’交换,从而产生错误。
所以需要进行特判数组长度是否为1,如果为1,则不进行交换位置。

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

char s[15], t[15];

int main(void)
{
	int len, cnt = 0;
	cin >> s;
	len = strlen(s);
	sort(s, s + len);
	for (int i = 0; i < len; i++)
	{
		if (s[i] == '0')
			cnt++;
	}
	if (cnt && len != 1)
		swap(s[0], s[cnt]);
	cin >> t;
	if (strcmp(s, t) == 0)
		cout << "OK" << endl;
	else
		cout << "WRONG_ANSWER" << endl;
	return 0;
}

C - Fruits

The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.

When he came to the fruit stall of Ashot, he saw that the seller hadn’t distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags).

Input

The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera’s list. The second line contains n space-separated positive integer numbers. Each of them doesn’t exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn’t exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.

Output

Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.

Examples

Input

5 3
4 2 1 10 5
apple
orange
mango

Output

7 19

Input

6 5
3 5 1 6 8 1
peach
grapefruit
banana
orange
orange

Output

11 30

我用了一个sarr数组来记录所有的水果,用map来记录每种水果需要购买的数目。
计算最小花费时,用最大的数目对应最小的花费,计算最大花费时,用最大的数目对应最大的花费。

#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int arr[105];//价格数组
map<string, int> M;//每种水果对应的价格
string sarr[105];//string数组,即水果数组

bool cmp1(string a, string b)
{
	return M[a] > M[b];
}

bool cmp2(int a, int b)
{
	return a > b;
}

int main(void)
{
	string t;//每次输入的水果
	int n, m, cnt = 0;
	int mi = 0, ma = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < m; i++)
	{
		cin >> t;
		if (M[t] == 0)
			sarr[cnt++] = t;
		M[t]++;//每种水果的数目
	}
	
	sort(arr, arr + n);
	sort(sarr, sarr + cnt, cmp1);
	for (int i = 0; i < cnt; i++)
		mi += M[sarr[i]] * arr[i]; 
		
	sort(arr, arr + n, cmp2);
	for (int i = 0; i < cnt; i++)
		ma += M[sarr[i]] * arr[i];
		
	cout << mi << " " << ma << endl;
	return 0;
}

E - Start of the season

Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size n × n (n is even number). Gods will never allow to start the championship without it. Matrix should contain integers from 0 to n - 1, main diagonal should contain only zeroes and matrix should be symmetric. Moreover, all numbers in each row should be different. Magicians are very tired of the thinking process, so they ask you to write a program to find such matrix.

Input

The first line contains one integer n (2 ≤ n ≤ 1000), n is even.

Output

Output n lines with n numbers each — the required matrix. Separate numbers with spaces. If there are several solutions, output any.

Examples

Input

2

Output

0 1
1 0

Input

4

Output

0 1 3 2
1 0 2 3
3 2 0 1
2 3 1 0
题解:
https://blog.csdn.net/nealgavin/article/details/8494306
http://www.mamicode.com/info-detail-2686317.html

思维题,感觉不好想出来。
用cout耗时842ms,好险。

#include <iostream>
using namespace std;
const int N =1e3 + 5;

int m[N][N];

int main(void)
{
	int n;
	cin >> n;
	n--;//先自减 
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)//每一行向左错1位 
			m[i][j] = (i + j) % n + 1;
	}
	for (int i = 0; i < n; i++)
    {	
		m[i][n] = m[n][i] = m[i][i];//将主对角线的数字放到最右边一列和最下边一行
		m[i][i] = 0;//并将主对角线全设为0 
	}
	for (int i = 0; i <= n; i++)
    {
	    for (int j = 0; j <= n; j++)
	    	cout << m[i][j] << " ";
	    cout << endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值