[做题记录] 构造题选做
1. CF743C - Vladik and fractions (*1500)
目标:给定
Hint:
若
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
typedef long long ll;
typedef pair < int, int > PII;
typedef int itn;
mt19937 RND_MAKER (chrono :: steady_clock :: now ().time_since_epoch ().count ());
inline ll randomly (const ll l, const ll r) {return (RND_MAKER () ^ (1ull << 63)) % (r - l + 1) + l;}
//#define int long long
const double pi = acos (-1);
//__gnu_pbds :: tree < Key, Mapped, Cmp_Fn = std :: less < Key >, Tag = rb_tree_tag, Node_Upadte = null_tree_node_update, Allocator = std :: allocator < char > > ;
//__gnu_pbds :: tree < PPS, __gnu_pbds :: null_type, less < PPS >, __gnu_pbds :: rb_tree_tag, __gnu_pbds :: tree_order_statistics_node_update > tr;
signed main () {
int n;
scanf ("%d", &n);
if (n == 1) printf ("-1\n");
else printf ("%d %d %d\n", n, n + 1, n * (n + 1));
return 0;
}
2. CF1758D - Range = √Sum (*1800)
目标:给定
考虑奇偶分类。
当
极差:
和:
所以满足条件。
当
将所有数加
发现极差需要增加
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
typedef long long ll;
typedef pair < int, int > PII;
typedef int itn;
mt19937 RND_MAKER (chrono :: steady_clock :: now ().time_since_epoch ().count ());
inline ll randomly (const ll l, const ll r) {return (RND_MAKER () ^ (1ull << 63)) % (r - l + 1) + l;}
//#define int long long
const double pi = acos (-1);
//__gnu_pbds :: tree < Key, Mapped, Cmp_Fn = std :: less < Key >, Tag = rb_tree_tag, Node_Upadte = null_tree_node_update, Allocator = std :: allocator < char > > ;
//__gnu_pbds :: tree < PPS, __gnu_pbds :: null_type, less < PPS >, __gnu_pbds :: rb_tree_tag, __gnu_pbds :: tree_order_statistics_node_update > tr;
int _, n, a[300005];
signed main () {
scanf ("%d", &_);
while (_ --) {
scanf ("%d", &n);
if (n % 2 == 0) {
for (int i = n / 2;i <= 3 * n / 2; ++ i) {
if (i != n) printf ("%d ", i);
}
printf ("\n");
}
else {
for (int i = 1;i <= n; ++ i) a[i] = i;
int mid = n / 2 + 1;
int delta = n - mid;
for (int i = 1;i <= n; ++ i) a[i] += delta + 2;
a[1] --, a[n] ++;
a[n - 1] ++;
for (int i = 1;i <= n; ++ i) printf ("%d ", a[i]);
printf ("\n");
}
}
return 0;
}
3. CF1734E - Rectangular Congruence (*2100)
目标:给定质数
-
对于所有的
, 。 -
对于所有的
,有 。 -
对于所有的
, 。
对第二个条件进行变形,有:
所以对于一个合法的矩阵的同一行加上同一个数依然合法。
让第
剩下的操作就是调整每一行使得它满足第三个条件。
第一个条件就是
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
typedef long long ll;
typedef pair < int, int > PII;
typedef int itn;
mt19937 RND_MAKER (chrono :: steady_clock :: now ().time_since_epoch ().count ());
inline ll randomly (const ll l, const ll r) {return (RND_MAKER () ^ (1ull << 63)) % (r - l + 1) + l;}
//#define int long long
const double pi = acos (-1);
//__gnu_pbds :: tree < Key, Mapped, Cmp_Fn = std :: less < Key >, Tag = rb_tree_tag, Node_Upadte = null_tree_node_update, Allocator = std :: allocator < char > > ;
//__gnu_pbds :: tree < PPS, __gnu_pbds :: null_type, less < PPS >, __gnu_pbds :: rb_tree_tag, __gnu_pbds :: tree_order_statistics_node_update > tr;
int a[355][355], n, b[355];
signed main () {
scanf ("%d", &n);
for (int i = 1;i <= n; ++ i) {
for (int j = 1;j <= n; ++ j) {
a[i][j] = (i - 1) * (j - 1) % n;
}
}
for (int i = 1;i <= n; ++ i) {
scanf ("%d", &b[i]);
int delta = b[i] - a[i][i];
for (int j = 1;j <= n; ++ j) a[i][j] += delta;
}
for (int i = 1;i <= n; ++ i) {
for (int j = 1;j <= n; ++ j) {
a[i][j] = (a[i][j] % n + n) % n;
printf ("%d ", a[i][j]);
}
printf ("\n");
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下