Codeforces Round #313 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/560

水笔场。。。

A. Currency System in Geraldion

time limit per test:2 seconds

memory limit per test:256 megabytes

A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain
sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called
unfortunate. Gerald wondered: what is the minimum
unfortunate sum?

Input

The first line contains number
n (1?≤?n?≤?1000) — the number of values of the banknotes that used in Geraldion.

The second line contains n distinct space-separated numbers
a1,?a2,?...,?an (1?≤?ai?≤?106)
— the values of the banknotes.

Output

Print a single line — the minimum
unfortunate sum. If there are no unfortunate sums, print
?-?1.

Sample test(s)

Input

5
1 2 3 4 5

Output

-1

题目大意:n种纸币每个面值为ai,问最小的不能组成的面值大小

题目分析:有1输-1,没1输1

#include <cstdio>

int main()
{
	int ans = 1, n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		int get;
		scanf("%d", &get);
		if(get == 1)
			ans = -1;
	}
	printf("%d\n", ans);
}

B. Gerald is into Art

time limit per test:2 seconds

memory limit per test:256 megabytes

Gerald bought two very rare paintings at the Sotheby‘s auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of
an a1?×?b1 rectangle, the paintings have shape of a
a2?×?b2 and
a3?×?b3 rectangles.

Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings
can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?

Input

The first line contains two space-separated numbers
a1 and
b1 — the sides of the board. Next two lines contain numbers
a2,?b2,?a3 and
b3 — the sides of the paintings. All numbers
ai,?bi in the input are integers and fit into the range from
1 to 1000.

Output

If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).

Sample test(s)

Input

3 2
1 3
2 1

Output

YES

Input

5 5
3 3
3 3

Output

NO

Input

4 2
2 3
1 2

Output

YES

Note

That‘s how we can place the pictures in the first test:

And that‘s how we can do it in the third one.

题目大意:三个矩形,给出边长,问后两个能不能放到第一个里

题目分析:懒得说,就那么点情况而已

#include <cstdio>
#include <algorithm>
using namespace std;
int a1, a2, a3, b1, b2, b3;

bool J(int x, int y)
{
	return (x <= a1 && y <= b1 || x <= b1 && y <= a1);
}

int main()
{
	scanf("%d %d %d %d %d %d", &a1, &b1, &a2, &b2, &a3, &b3);
	if(J(a2 + a3, max(b2, b3))
		|| J(b2 + b3, max(a2, a3))
		|| J(a2 + b3, max(b2, a3))
		|| J(a3 + b2, max(b3, a2)))
		printf("YES\n");
	else
		printf("NO\n");
}

C. Gerald‘s Hexagon

time limit per test:2 seconds

memory limit per test:256 megabytes

Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to
. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters.
There the properties of the hexagon ended and Gerald decided to draw on it.

He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that
Gerald lost the track of his counting. Help the boy count the triangles.

Input

The first and the single line of the input contains 6 space-separated integers
a1,?a2,?a3,?a4,?a5 and
a6 (1?≤?ai?≤?1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed
that the hexagon with the indicated properties and the exactly such sides exists.

Output

Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.

Sample test(s)

Input

1 1 1 1 1 1

Output

6

Input

1 2 1 2 1 2

Output

13

Note

This is what Gerald‘s hexagon looks like in the first sample:

And that‘s what it looks like in the second sample:

题目大意:给出六边形6个边长,求里面有多少个边长为1的正三角形

题目分析:这题还有点意思,把它补成大正三角形,大正三角形包含的小三角个数为边长^2,等差数列求和,因为边按顺序给的,通过旋转我们可以发现大边长等于a1+a2+a3,多出来的另外三个正三角形的边长为a1,a3,a5,所以最后答案就是(a1+a2+a3)^2-a1^2-a3^2-a5^2

#include <cstdio>
#include <cstring>
int const MAX = 3005;
int fac[MAX];

int main()
{
	for(int i = 1; i <= MAX; i++)
		fac[i] = i * i;
	int a[7];
	for(int i = 1; i <= 6; i++)
		scanf("%d", &a[i]);
	printf("%d\n", fac[a[1] + a[2] + a[3]] - fac[a[1]] - fac[a[3]] - fac[a[5]]);
}

D. Equivalent Strings

time limit per test:2 seconds

memory limit per test:256 megabytes

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings
a and b of equal length are called
equivalent in one of the two cases:

  1. They are equal.
  2. If we split string a into two halves of the same size
    a1 and
    a2, and string
    b into two halves of the same size b1 and
    b2, then one of the following is correct:

    1. a1 is equivalent to
      b1, and
      a2 is equivalent to
      b2
    2. a1 is equivalent to
      b2, and
      a2 is equivalent to
      b1

As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.

Gerald has already completed this home task. Now it‘s your turn!

Input

The first two lines of the input contain two strings given by the teacher. Each of them has the length from
1 to 200?000 and consists of lowercase English letters. The strings have the same length.

Output

Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.

Sample test(s)

Input

aaba
abaa

Output

YES

Input

aabb
abab

Output

NO

Note

In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab"
and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba"
as "ab" = "a" + "b", "ba" = "b" + "a".

In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That‘s why string "aabb"
is equivalent only to itself and to string "bbaa".

题目大意:给两个字符串,判断它们是否相等,相等有两种情况,一个是直接相等,一个是切成长度相同的两份以后两子串交叉相等

题目分析:裸的DFS,按照题意搜就行了,如果当前长度为奇数,直接返回false,否则分两种情况搜

#include <cstdio>
#include <cstring>
int const MAX = 250000;
char a[MAX], b[MAX];

bool DFS(char *p1, char *p2, int len)
{
    if(!strncmp(p1, p2, len))
    	return true;
    if(len % 2)
    	return false;
    int n = len / 2;
    if(DFS(p1 ,p2 + n, n) && DFS(p1 + n, p2, n))
    	return true;
    if(DFS(p1, p2, n) && DFS(p1 + n, p2 + n, n))
    	return true;
    return false;
}

int main()
{
    scanf("%s %s", a, b);
    printf("%s\n", DFS(a, b, strlen(a)) ? "YES" : "NO");
}

E题会补的。。。

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-12 07:19:20

Codeforces Round #313 (Div. 2) (ABCD题解)的相关文章

Codeforces Round #Pi (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/567 听说Round #Pi的意思是Round #314... A. Lineland Mail time limit per test:3 seconds memory limit per test:256 megabytes All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with it

Codeforces Round #250 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory limit per test:256 megabytes Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between th

Codeforces Round #249 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/435 A. Queue on Bus Stop time limit per test:1 second memory limit per test:256 megabytes It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of p

Codeforces Round #302 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/544 A. Set of Strings time limit per test:1 second memory limit per test:256 megabytes You are given a string q. A sequence of k strings s1,?s2,?...,?sk is called beautiful, if the concatenation of these strings is

Codeforces Round #533 (Div. 2) ABCD 题解

题目链接 A. Salem and Sticks 分析 暴力就行,题目给的n<=1000,ai<=100,暴力枚举t,t从2枚举到98,复杂度是1e5,完全可行. 代码 1 #include <cstdio> 2 #include <cmath> 3 #include <iostream> 4 #include <cstring> 5 #include <algorithm> 6 #include <vector> 7 #

Codeforces Round #313 (Div. 1)

官方英文题解:http://codeforces.com/blog/entry/19237 Problem A: 题目大意: 给出内角和均为120°的六边形的六条边长(均为正整数),求最多能划分成多少个边长为1的正三角形. 题解: 把六边形补全变成一个正三角形,然后减去三个角的正三角形即可. Problem B: 题目大意: 给出长度相等的两个串AB,定义两个串相等 当且仅当  A=B  或者  当长度为偶数时,A[1...n/2]=B[1...n/2]  && A[n/2+1...n]=

Codeforces Round #313 (Div. 2) Gerald&#39;s Hexagon

给出一个六边形六条边的长度(六边形的每个角为120度),求出这个六边形中边长为1的等边三角形有多少个 由于每个角都是120度并且上下两条边是平行的,因此我们可以补出一个矩形,再减掉周边四个角的面积,用剩下面积除以每个小三角形的面积. #include<cstdio> using namespace std; double a,b,c,d,e,f; int main() { <span style="white-space:pre"> </span>s

Codeforces Round #313 (Div. 2) C Gerald&#39;s Hexagon 计数

// Codeforces Round #313 (Div. 2) C Gerald's Hexagon // 计数 // 关键是平行于a1的长度为1的有多少条,中间的这些*2,再加上a1 // 和a4,就是三角形的总和 // 还是挺简单的,注意递增的初始值,和变化,就ac了 #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> using namespac

Codeforces Round #258 (Div. 2)[ABCD]

Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意: Akshat and Malvika两人玩一个游戏,横竖n,m根木棒排成#型,每次取走一个交点,交点相关的横竖两条木棒要去掉,Akshat先手,给出n,m问谁赢. 分析: 水题,很明显不管拿掉哪个点剩下的都是(n-1,m-1),最后状态是(0,x)或(x,0),也就是拿了min(n,m)-1次,