StarryCoding 入门教育赛 2

比赛地址:https://www.starrycoding.com/contest/6

A. 平方和判定

题意:

给定 a , b , c , 判断 a 2 + b 2 > c 2 给定a, b, c,判断 a^2 + b^2 > c ^ 2 给定a,b,c,判断a2+b2>c2

思路:

模拟

Accepted代码:

#include <bits/stdc++.h>
using namespace std;

// #define x first
// #define y second
// #define int long long
#define endl '\n'

typedef long long LL;
typedef pair<int, int> PII;

const int INF = 0x3f3f3f3f, MOD = 998244353;
const int N = 1e5 + 5;

void oper()
{
	LL a, b, c;
	cin >> a >> b >> c;

	if (a * a + b * b > c * c)	cout << "YES" << endl;
	else 						cout << "NO" << endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// int T = 1;
	int T;	cin >> T;
	while (T --)	oper();

	return 0;
}

B. 矩阵判定

题意:

给定 n ∗ m 的矩阵,对于任意的 1 ≤ i 1 < i 2 ≤ n , 1 ≤ j 1 < j 2 ≤ m , 有 A i 1 j 1 + A i 2 j 2 > A i 2 j 1 + A i 1 j 2 给定 n * m 的矩阵,对于任意的 1 \leq i_1 < i_2 \leq n, 1 \leq j_1 < j_2 \leq m, 有A_{i_1j_1} + A_{i_2j_2} > A_{i_2j_1} + A_{i_1j_2} 给定nm的矩阵,对于任意的1i1<i2n,1j1<j2m,Ai1j1+Ai2j2>Ai2j1+Ai1j2

思路:

暴力枚举

Accepted代码:

#include <bits/stdc++.h>
using namespace std;

// #define x first
// #define y second
// #define int long long
#define endl '\n'

typedef long long LL;
typedef pair<int, int> PII;

const int INF = 0x3f3f3f3f, MOD = 998244353;
const int N = 50 + 5;

int n, m;
int a[N][N];

void oper()
{
	cin >> n >> m;

	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++)
			cin >> a[i][j];

	for (int i1 = 1; i1 <= n - 1; i1 ++)
		for (int i2 = i1 + 1; i2 <= n; i2 ++)
			for (int j1 = 1; j1 <= m - 1; j1 ++)
				for (int j2 = j1 + 1; j2 <= m; j2 ++)
				{
					if (a[i1][j1] + a[i2][j2] <= a[i2][j1] + a[i1][j2])
					{
						cout << "NO" << endl;
						return ;
					}
				}

	cout << "YES" << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// int T = 1;
	int T;	cin >> T;
	while (T --)	oper();

	return 0;
}

C. 曼哈顿种类

题意:

给定 n 个坐标,求任两点间的曼哈顿距离的种类数

思路:

模拟去重

Accepted代码:

#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
// #define int long long
#define endl '\n'

typedef long long LL;
typedef pair<int, int> PII;

const int INF = 0x3f3f3f3f, MOD = 998244353;
const int N = 50 + 5;

int n;

LL f(PII a, PII b)
{
	return abs(a.x - b.x) + abs(a.y - b.y);
}

void oper()
{
	cin >> n;

	LL x, y;
	vector<PII> v;
	for (int i = 1; i <= n; i ++)
	{
		cin >> x >> y;
		v.push_back({x, y});
	}

	set<LL> set;
	for (int i = 0; i < v.size() - 1; i ++)
		for (int j = i + 1; j < v.size(); j ++)
		{
			LL dis = f(v[i], v[j]);
			set.insert(dis);
		}

	cout << set.size() << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// int T = 1;
	int T;	cin >> T;
	while (T --)	oper();

	return 0;
}

D. 小e消消乐

题意:

1、如果弹珠数量小于2,那么结束这次操作。

2、如果最后2个弹珠的大小不相等,那么结束这次操作。

3、如果最后2个弹珠的大小相等,那么就把这2个弹珠合并,变成一个大小为两个弹珠之和的大弹珠。然后,回到第1步重复这3个步骤。

思路:

栈,模拟

Accepted代码:

#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
// #define int long long
#define endl '\n'

typedef long long LL;
typedef pair<int, int> PII;

const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 1e5 + 5;

int n;
LL a[N];

LL qmi(int a, int k, int p)
{
	LL res = 1;

	while (k)
	{
		if (k & 1)	res = (LL)res * a % p;

		k >>= 1;

		a = (LL)a * a % p;
	}

	return res;
}

void oper()
{
	cin >> n;

	int index = 1;
	for (int i = 1; i <= n; i ++)	cin >> a[i];

	stack<LL> stk;
	LL t = pow(2, a[index ++]);
	stk.push(t);

	while (stk.size())
	{	
		if (stk.size() < 2)
		{
			if (index >= n + 1)	
			{
				cout << stk.size() << endl;
				return ;
			}
			LL t = pow(2, a[index ++]);
			stk.push(t);
		}
		else if (stk.size() >= 2)
		{
			int t1 = stk.top(); 
			stk.pop();
			int t2 = stk.top(); 
			stk.pop();

			if (t1 != t2)
			{
				stk.push(t2);
				stk.push(t1);

				if (index >= n + 1)	
				{
					cout << stk.size() << endl;
					return ;
				}

				LL t = pow(2, a[index ++]);
				stk.push(t);

			}
			else
			{
				stk.push(t1 + t2);
			}
		}
	}

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int T = 1;
	// int T;	cin >> T;
	while (T --)	oper();

	return 0;
}

E. 妹妹太多怎么办呐!

题意:

给定n个坐标,价值,从当前坐标走到目标地花费曼哈顿距离,获得目的地价值,必须走过k个坐标,求总价值最大的方案

思路:

深搜,记录当前坐标、价值和目前走的坐标数

Accepted代码:

#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
// #define int long long
#define endl '\n'

typedef long long LL;
typedef pair<int, int> PII;

const int INF = 0x3f3f3f3f, MOD = 998244353;
const int N = 50 + 5;

int n, k;
LL ans;
bool st[N];

vector<pair<PII, int>> v;

LL manha(LL x1, LL y1, LL x2, LL y2)
{
	return abs(x1 - x2) + abs(y1 - y2);
}

void dfs(int cnt, LL xx, LL yy, LL now)
{
	if (cnt == k)
	{
		ans = max(ans, now);
		return ;
	}

	for (int i = 1; i <= n; i ++)
	{
		if (st[i])	continue;

		int index = i - 1;
		LL g_x = v[index].x.x;
		LL g_y = v[index].x.y;
		LL g_w = v[index].y;

		LL dis = manha(xx, yy, g_x, g_y);
		
		st[i] = true;
		
		dfs(cnt + 1, g_x, g_y, now - dis + g_w);

		st[i] = false;
	}

}	

void oper()
{
	cin >> n >> k;

	ans = LLONG_MIN;

	for (int i = 1; i <= n; i ++)	st[i] = false;
	v.clear();

	LL a, b, c;
	for (int i = 1; i <= n; i ++)
	{
		cin >> a >> b >> c;
		v.push_back({{a, b}, c});
	}

	dfs(0, 0, 0, 0);

	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// int T = 1;
	int T;	cin >> T;
	while (T --)	oper();

	return 0;
}
  • 24
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值