\(\large \texttt{T1 P8813 [CSP-J 2022] 乘方}\)

原题链接

#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
int a, b, c;
int pow(int a, int b)
{
    int ans = 1;
    for (int i = 1;i <= b;i ++)
    {
        ans *= a;
        if (ans > 1e9) return -1;
    }
    return ans;
}
signed main()
{
    scanf("%lld %lld",&a,&b);
    cout << pow(a, b);
}

\(\large \texttt{T2 P8814 [CSP-J 2022] 解密}\)

原题链接

#include<iostream>
#include<cmath>
#define int long long
using namespace std;
int k, n, d, e;
int check(int y) {int x = sqrt(y); return x * x == y; }
void solve(int n, int d, int e)
{
	int a = n + 2 - e * d;
	int b = e * d;
	int c = a + b - 2;
	if (a * a - 4 * c >= 0 && check(a * a - 4 * c))
	{
		int t, p, q;
		t = a + sqrt(a * a - 4 * c);
		if (t % 2) 
		{
			cout << "NO\n";
			return;
		}
		q = t / 2, p = a - q;
		if (p > q) 
		{
			cout << "NO\n";
			return;
		}
		cout << p << " " << q << endl;
		return;
	}
	cout << "NO\n";
}
signed main(void)
{
	cin >> k;
	while (k --)
	{
		cin >> n >> d >> e;
		solve(n, d, e);
	}
}

\(\large \texttt{T3 P8815 [CSP-J 2022] 逻辑表达式}\)

原题链接

#include<bits/stdc++.h>
using namespace std;
struct node {
	int value, cnt_or, cnt_and;
};
stack<node> str;
string expr;
int getpriority(char a)
{
	if (a == '(') return 0;
	if (a == '|') return 1;
	return 2;
}
string turn_into(string expr)
{
	string ret;
	stack<char> st;
	for (auto c:expr)
	{
		if (c == '(') st.push(c);
		else if (c == ')')
		{
			while (st.top() != '(')
			{
				ret.push_back(st.top());
				st.pop();
			}
			st.pop();
		}
		else if (c == '&' || c == '|')
		{
			while (!st.empty() && getpriority(c) <= getpriority(st.top()))
			{
				ret.push_back(st.top());
				st.pop();
			}
			st.push(c);
		}
		else ret.push_back(c);
	}
	while (!st.empty())
	{
		ret.push_back(st.top());
		st.pop();
	}
	return ret;
}
int main()
{
	cin >> expr;
	string skl = turn_into(expr);
	for (auto c:skl)
	{
		if (c == '|')
		{
			node r = str.top();str.pop();
			node l = str.top();str.pop();
			str.push({l.value | r.value, l.cnt_or + (l.value == 1 ? 1 : r.cnt_or), l.cnt_and + (l.value == 1 ? 0 : r.cnt_and)});
		}
		else if (c == '&')
		{
			node r = str.top();str.pop();
			node l = str.top();str.pop();
			str.push({l.value & r.value, l.cnt_or + (l.value == 0 ? 0 : r.cnt_or),l. cnt_and + (l.value == 0 ? 1 : r.cnt_and)});
		}
		else str.push({c - '0', 0, 0});
	}
	node ans = str.top();
	cout << ans.value << endl;
	cout << ans.cnt_and << " " << ans.cnt_or << endl;
	return 0;
}

\(\large \texttt{T4 P8816 [CSP-J 2022] 上升点列}\)

原题链接

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
struct _pnt {
	int x, y;
}a[1010];
int n, k, ans = 0;
int f[550][550];
int dis(int i, int j) { return abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y) - 1; }
bool cmp(_pnt p1, _pnt p2) {
	if (p1.x == p2.x) return p1.y < p2.y;
	else return p1.x < p2.x;
}
int main()
{
	scanf("%d %d", &n, &k);
	for (int i = 1;i <= n;i ++) scanf("%d %d", &a[i].x, &a[i].y);
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1;i <= n;i ++)
	{
		int x = a[i].x;
		int y = a[i].y;
		for (int z = 0;z <= k;z ++)
		{
			f[i][z] = 1;
			for (int j = 1;j <= n;j ++)
			{
				if (i != j && a[j].x <= x && a[j].y <= y)
				{
					int len = dis(i, j);
					if (z >= len)
					{
						f[i][z] = max(f[i][z], f[j][z - len] + len + 1);
					}
				}
			}
			ans = max(ans, f[i][z] + k - z);
		}
	}
	printf("%d\n", ans);
	return 0;
}

原文地址:http://www.cnblogs.com/kkksc007/p/16923060.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性