Codeforces 1325 Div.2 notes

Codeforces 1325 Div.2 notes

Impressions

But also points out a. Because remember correctly, the time was an hour late, only made the problem AB. The feeling of too great amount of thinking, feeling better get out of this problem is A and C title (D title since then did not see). There are requirements stable, B submitted a title five times, did not score at all. Future should pay attention. 1300Rating fell, and with the 1900 feel from getting bigger.

topic

A EhAb AnD gCd

Resolve

Given an integer n n , requires two integers x , Y x, y , such that G c d ( x , Y ) + L c m ( x , Y ) = n Gcd (x, y) + Lcm (x, y) = n

At first glance, the data is relatively large, 1 n 1 0 9 1 \ n \ 10 ^ 9 , and sets Gcd Lcm then definitely timeout, but careful thought for a moment, Gcd (1, n - 1must be 1, Lcm (1, n -must be n - 1, add up just fine.

Code

#include <bits/stdc++.h>

typedef long long ll;

ll nextInt()
{
	ll num = 0;
	char c = 0;
	bool flag = false;
	while ((c = std::getchar()) == ' ' || c == '\r' || c == '\t' || c == '\n');
	if (c == '-')
		flag = true;
	else
		num = c - 48;
	while (std::isdigit(c = std::getchar()))
		num = num * 10 + c - 48;
	return (flag ? -1 : 1) * num;
}

int main(int argc, char **argv)
{
	int t = nextInt();
	while (t--)
	{
		ll n = nextInt();
		std::cout << 1 << ' ' << n - 1 << std::endl;
	}
}

B CopyCopyCopyCopyCopy

Resolve

Given a set of numbers A i A_i ,by n n the number of components. Obtained copies the array n n later times, the new array is formed in the longest rise strict sequence.

I have made this title five times. The first time n 2 n^2 LIS, and timeout. The second time n l o g 2 n n log_2 n the LIS, timeout. The third time I have found, since it is a copy n n times, so no need to seek a more, ah, look at the top as long as it can constitute a rise to take. So a map sentenced to pay a heavy timeout. Later changed to set the output size (), metaphysics timeout. Changed a bit the set is defined on the outside, he had a hand in the herd. To feel good and then further turned over.

Code

#include <bits/stdc++.h>

typedef long long ll;

ll nextInt()
{
	ll num = 0;
	char c = 0;
	bool flag = false;
	while ((c = std::getchar()) == ' ' || c == '\r' || c == '\t' || c == '\n');
	if (c == '-')
		flag = true;
	else
		num = c - 48;
	while (std::isdigit(c = std::getchar()))
		num = num * 10 + c - 48;
	return (flag ? -1 : 1) * num;
}

std::set<int> s;

int main(int argc, char **argv)
{
	int T = nextInt();
	while (T--)
	{
		s.clear();
		ll n = nextInt();
		for (int i = 1; i <= n; i++)
		{
			ll x = nextInt();
			s.insert(x);
		}
		std::cout << s.size() << std::endl;
	}
}

C Ehab and Path-etic MEXs

Resolve

Have given a n n nodes n 1 n-1 edges of the tree, the requirements on all sides superscript 0 , 1 , 2 , , n 2 0,1,2,\ldots , n-2 , the definition of M E X ( u , v ) MEX(u,v) for the tree, u to v except the path to go through a simple edge, the minimum value of all edges of the tree, such that for any u , v u, v of M E X u v MEX(u,v) the maximum value of as small as possible.

This problem reading the title studying the light 40min, last but not out of tune. The next day found that thought for a moment, count a number of visits, the number is 1 point is the leaf node, so that each path through which a leaf node becomes the minimum distance can be.

Code

#include <bits/stdc++.h>

typedef long long ll;

ll nextInt()
{
	ll num = 0;
	char c = 0;
	bool flag = false;
	while ((c = std::getchar()) == ' ' || c == '\r' || c == '\t' || c == '\n');
	if (c == '-')
		flag = true;
	else
		num = c - 48;
	while (std::isdigit(c = std::getchar()))
		num = num * 10 + c - 48;
	return (flag ? -1 : 1) * num;
}

size_t _Siz = 109231;

int main(int argc, char **argv)
{
	int vis[_Siz] = { 0 }, ans[_Siz] = { 0 }, pos[_Siz] = { 0 };
	std::memset(ans, 0xff, sizeof ans);
	int n = nextInt();
	for (int i = 1; i < n; i++)
	{
		int x = nextInt(), y = nextInt();
		vis[x]++;
		vis[y]++;
		pos[x] = i, pos[y] = i;
	}
	int tot = 0;
	for (int i = 1; i <= n; i++)
		if (vis[i] == 1)
			ans[pos[i]] = tot++;
	for (int i = n - 1; i >= 1; i--)
		if (ans[i] == -1)
			ans[i] = tot++;
	for (int i = 1; i < n; i++)
	{
		if (ans[i] == n - 1)
			ans[i] = 0;
		std::cout << ans[i] << '\n';
	}
	return 0;
}

D Ehab the Xorcist

Resolve

Configured as a short length of n n array, such that all of the elements of the array to a given value and v v , all of the elements and the exclusive OR value for a given u in .

Think after last night, go to bed, it must first determine whether or not solvable. Because if v < u v < u word is certainly no solution.

Secondly, if the exclusive OR is 1 and the bit, the array, the number of 1 bits must is odd, and the bit should be 1. Similarly, if the exclusive OR of bits and is 0, and the bit should be zero.

So, if and only if v u v\ge u ( v u ) 2 (Vu) | 2 in the case of, u , v u, v solvable.

Obviously, u , v u, v case solvability, u , ( v u ) / 2 , ( v u ) / 2 {U, (vu) / 2, (vu) / 2} is a construction always solvable, so we only need to consider the special sentence n < 3 n<3 situation.

Solvable in the case of u = v = 0: n = 0.

n = 1: solvable in the case of u = v.

n = 2: {/ 2 (v + u) / 2, (vu)} satisfies the condition established in the case.

Code

#include <bits/stdc++.h>

typedef long long ll;

ll nextInt()
{
	ll num = 0;
	char c = 0;
	bool flag = false;
	while ((c = std::getchar()) == ' ' || c == '\r' || c == '\t' || c == '\n');
	if (c == '-')
		flag = true;
	else
		num = c - 48;
	while (std::isdigit(c = std::getchar()))
		num = num * 10 + c - 48;
	return (flag ? -1 : 1) * num;
}

ll n, m;
int main(int argc, char **argv) 
{
	n = nextInt();
	m = nextInt();
    if (n > m || (m - n) % 2 != 0)
	{
        puts("-1");
        return 0;
    } 
	else if (n == m && n == 0) 
	{
        puts ("0");
    } 
	else if (n == m) 
	{
        std::cout << 1 << '\n' << n << '\n';
    } 
	else 
	{
        long long x = (n + m) / 2, y = n;
        long long a = x, b = x - y;
        if ((a + b) == m && (a ^ b) == n)
            std::cout << 2 << '\n' << a << ' ' << b << '\n';
        else
            std::cout << 3 << '\n' << n << ' '  << (m - n) / 2 << ' ' <<  (m - n) / 2);
        return 0;
    }
    return 0;
}
Published 40 original articles · won praise 0 · Views 5128

Guess you like

Origin blog.csdn.net/edward00324258/article/details/104888757