直接输出
| _ ____ _____ _____ |
| | | _ \ / ____|/ ____| |
| | | |_) | | __| | __ |
| _ | | _ <| | |_ | | |_ | |
| | |__| | |_) | |__| | |__| | |
| \____/|____/ \_____|\_____| |
将原矩阵的每个字符输出两次,同时每行也输出两次
#include
using namespace std;
using i64 = long long;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m;
std::cin >> n >> m;
for (int i = 0; i < n; i ++) {
string s;
std::cin >> s;
for (int u = 0; u < 2; u ++) {
for (int j = 0; j < m; j ++) {
for (int k = 0; k < 2; k ++) {
std::cout << s[j];
}
}
std::cout << "\n";
}
}
return 0;
}
由于题目数据小,不搞一些花哨操作,直接判断每组寻问中是否有被抓的可能
#include
using namespace std;
using i64 = long long;
void solve()
{
int a,b,c,d;
std::cin >> a >> b >> c >> d;
int q;
std::cin >> q;
bool ok = false;
while (q -- ) {
int x;
std::cin >> x;
if ((x >= a and x <= b) or (x >= c and x <= d)) ok = true;
}
if (ok) std::cout << "Y\n";
else std::cout << "N\n";
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T -- ) {
solve();
}
return 0;
}
#include
using namespace std;
#define int long long
void solve()
{
int n,m,x;
std::cin >> n >> m >> x;
std::vector<int> a(n + 10),b(m + 10),A(x + 10),S(x + 10);
for (int i = 1; i <= n; i ++) {
std::cin >> a[i];
}
for (int j = 1; j <= m; j ++) {
std::cin >> b[j];
}
for (int i = 1; i <= x; i ++) {
for (int j = 1; j <= n; j ++) {
if (i <= a[j] or S[i - a[j]] == 0) {
A[i] = 1;
}
}
for (int j = 1; j <= m; j ++) {
if (i <= b[j] or A[i - b[j]] == 0) {
S[i] = 1;
}
}
}
if (A[x]) std::cout << "AsindE\n";
else std::cout << "slwang\n";
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T -- ) {
solve();
}
return 0;
}
bi为a中下标为i的倍数的元素和
,即b1 = a(1-n),b2 = a(2,4…).所以b1包含了a数组的所有元素。 我们可以通过
消除其他项与b1共有的数。如图
要消去b4中的a8,b3中的a6,b2中的a4,a6,a8.最后通过b1便可得出a1
#include
using namespace std;
#define int long long
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> b(n + 1);
for (int i = 1; i <= n; i ++) {
std::cin >> b[i];
}
for (int i = n; i >= 1; i --) {//逆序消
for (int j = i + i; j <= n; j += i) {
b[i] -= b[j];
}
}
std::cout << b[1] << "\n";
return 0;
}
按照题意模拟即可
#include
using namespace std;
using i64 = long long;
void solve()
{
string s;
std::cin >> s;
int n = s.size();
for (int i = 0; i < n; i ++) {
if (!i) {
s[i] = tolower(s[i]);
continue;
}
if (s[i] >= 'A' and s[i] <= 'Z') {
s[i] = tolower(s[i]);
s[i - 1] = toupper(s[i - 1]);
}
}
s[n - 1] = toupper(s[n - 1]);
std::cout << s << "\n";
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T -- ) {
solve();
}
return 0;
}
dfs; 明显可以看出答案是一条链,我们应该找到一个入度为0的点进行搜,取搜到的最大值即可。
这里直接以每一个点作为根节点搜了起来
#include
using namespace std;
#define int long long
const int N = 5e3 + 10;
std::vector<int> a(N);
std::vector<std::vector<pair<int,int>>> g(N);
std::vector<int> f(N);
int res = 0;
void dfs(int u,int fa)
{
int ans = 0;
for (auto [k,v] : g[u]) {
if (k == fa) continue;
dfs(k,u);
res = std::max(res,ans + a[u] + v + f[k]);
ans = std::max(ans,f[k] + v);
f[u] = std::max(f[u],ans);
}
f[u] += a[u];
res = std::max(res,f[u]);
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
for (int i = 1; i <= n; i ++) {
std::cin >> a[i];
}
for (int i = 1; i < n; i ++) {
int a,b,c;
std::cin >> a >> b >> c;
g[a].push_back({b,c});
g[b].push_back({a,c});
}
dfs(1,1);
std::cout << res << "\n";
return 0;
}
一种简单的解法:直接用1和-1构造这个矩阵,容易知道,只有当1和-1交替出现时才能满足题意
#include
using namespace std;
#define int long long
void solve()
{
int n,m;
std::cin >> n >> m;
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
std::cout << ((i + j) % 2 ? "1" : "-1")<< " \n"[j == m];
}
}
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T -- ) {
solve();
}
return 0;
}
I题最后没时间写了,有空再补
考虑使用并查集,最后输出每个的祖先
#include
using namespace std;
#define int long long
const int N = 2e5 + 10;
int pre[N];
int find(int x)
{
return x == pre[x] ? pre[x] : pre[x] = find(pre[x]);
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m;
std::cin >> n >> m;
std::vector<int> a(n + 1);
for (int i = 1; i < N; i ++) {
pre[i] = i;
}
for (int i = 1; i <= n; i ++) {
std::cin >> a[i];
}
while (m --) {
int a,b;
std::cin >> a >> b;
int fa = find(a);
int fb = find(b);
if (fa != fb) {
pre[fa] = fb;
}
}
for (int i = 1; i <= n; i ++) {
std::cout << find(a[i]) << " \n"[i == n];
}
return 0;
}
数学题,a与a + x互质等价于x 与 a 互质,所以暴力找与x互质的数即可
#include
using namespace std;
using i64 = long long;
void solve()
{
int n;
std::cin >> n;
for (int i = 2; ; i ++) {
if (__gcd(i,n) == 1) {
std::cout << i << " " << i + n << "\n";
return;
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T -- ) {
solve();
}
return 0;
}
将n拼起来,取模找最大值,枚举到m与p的最小值
#include
using namespace std;
#define int long long
//a^b%p
template<class T>
T qmi(T a, int b,T p) {
T res = 1 % p;
while (b)
{
if (b & 1) res = res * a % p;
a = a * a % p;
b >>= 1;
}
return res;
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m,p;
std::cin >> n >> m >> p;
int t = n,c = 0;
while (t) {
t /= 10;
c ++;
}
int w = qmi(1ll * 10,c,p),res = 0;
for (int i = 1; i <= std::min(m,p); i ++) {
t = (t * w + n) % p;
res = std::max(res,t);
}
std::cout << res << "\n";
return 0;
}
几何题能不能死一死