mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-07 18:06:58 +08:00
Upload via code
This commit is contained in:
BIN
Luogu/.DS_Store
vendored
Normal file
BIN
Luogu/.DS_Store
vendored
Normal file
Binary file not shown.
0
Luogu/F_Chips_on_a_Line.cpp
Normal file
0
Luogu/F_Chips_on_a_Line.cpp
Normal file
21
Luogu/Luogu_P_5715.cpp
Normal file
21
Luogu/Luogu_P_5715.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
using namespace std;
|
||||
|
||||
int arr[1005];
|
||||
int n;
|
||||
|
||||
signed main()
|
||||
{
|
||||
for(int i = 1; i <= 3; i ++ )
|
||||
{
|
||||
cin >> arr[i];
|
||||
}
|
||||
sort(arr + 1, arr + 1 + 3);
|
||||
for(int i = 1; i <= 3; i ++ )
|
||||
{
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
119
Luogu/Luogu_P_9912.cpp
Normal file
119
Luogu/Luogu_P_9912.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
using namespace std;
|
||||
|
||||
const int N = 10001005;
|
||||
|
||||
int n, q, l, r, mid, x, sum, ma, ans[N], o, cnt, cnt1;
|
||||
map<int, int> m;
|
||||
|
||||
// 结构体node用于存储线段树的节点信息
|
||||
struct node {
|
||||
int l, r, len, lc, rc; // l和r表示区间左右边界, len表示区间内岛屿的数量, lc和rc表示区间左右端点的类别
|
||||
} a[N];
|
||||
|
||||
// 结构体deno用于存储高度信息
|
||||
struct deno {
|
||||
int x, id; // x表示高度, id表示高度对应的位置索引
|
||||
} c[N];
|
||||
|
||||
// 结构体w用于存储查询信息
|
||||
struct w {
|
||||
int l, r, x, id; // l和r表示查询区间, x表示海平面上升高度, id表示查询的索引
|
||||
} b[N];
|
||||
|
||||
// 更新节点信息函数
|
||||
void gx(int p) {
|
||||
a[p].len = a[p * 2].len + a[p * 2 + 1].len; // 合并左右子区间的岛屿数量
|
||||
if (a[p * 2].rc == a[p * 2 + 1].lc) // 如果左右子区间的连接处高度相同,岛屿数量减少1
|
||||
a[p].len--;
|
||||
a[p].lc = a[p * 2].lc; // 更新左端点类别
|
||||
a[p].rc = a[p * 2 + 1].rc; // 更新右端点类别
|
||||
}
|
||||
|
||||
// 构建线段树函数
|
||||
void build(int p, int l, int r) {
|
||||
a[p].l = l;
|
||||
a[p].r = r;
|
||||
if (l == r) { // 叶子节点
|
||||
a[p].len = a[p].lc = a[p].rc = 1; // 初始化为长度为1的岛屿
|
||||
return;
|
||||
}
|
||||
int mid = (l + r) / 2;
|
||||
build(p * 2, l, mid); // 递归构建左子树
|
||||
build(p * 2 + 1, mid + 1, r); // 递归构建右子树
|
||||
gx(p); // 更新当前节点信息
|
||||
}
|
||||
|
||||
// 更新线段树函数
|
||||
void change(int p, int l, int r) {
|
||||
if (l <= a[p].l && a[p].r <= r) { // 完全覆盖
|
||||
a[p].len = 0; // 将区间内的长度设置为0
|
||||
a[p].lc = a[p].rc = ++cnt1; // 更新类别
|
||||
return;
|
||||
}
|
||||
int mid = (a[p].l + a[p].r) / 2;
|
||||
if (l <= mid) change(p * 2, l, r); // 递归更新左子树
|
||||
if (mid < r) change(p * 2 + 1, l, r); // 递归更新右子树
|
||||
gx(p); // 更新当前节点信息
|
||||
}
|
||||
|
||||
// 查询线段树函数
|
||||
int ask(int p, int l, int r) {
|
||||
if (l <= a[p].l && a[p].r <= r) // 完全覆盖
|
||||
return a[p].len;
|
||||
int mid = (a[p].l + a[p].r) / 2;
|
||||
int ans1 = 0;
|
||||
if (l <= mid && mid < r) { // 跨区间查询
|
||||
ans1 = ask(p * 2, l, r) + ask(p * 2 + 1, l, r); // 查询左右子树
|
||||
if (a[p * 2].rc == a[p * 2 + 1].lc) // 如果左右子树的连接处高度相同,岛屿数量减少1
|
||||
ans1--;
|
||||
} else if (l <= mid) { // 查询左子区间
|
||||
ans1 = ask(p * 2, l, r);
|
||||
} else if (mid < r) { // 查询右子区间
|
||||
ans1 = ask(p * 2 + 1, l, r);
|
||||
}
|
||||
return ans1;
|
||||
}
|
||||
|
||||
// 比较函数,用于排序查询
|
||||
bool cmp(w x, w y) {
|
||||
return x.x < y.x;
|
||||
}
|
||||
|
||||
// 比较函数,用于排序高度
|
||||
bool cmp1(deno x, deno y) {
|
||||
return x.x < y.x;
|
||||
}
|
||||
|
||||
signed main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
cin >> n >> q;
|
||||
cnt1 = n + 1;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> c[i].x;
|
||||
c[i].id = i;
|
||||
}
|
||||
sort(c + 1, c + 1 + n, cmp1); // 按高度排序
|
||||
for (int i = 1; i <= q; i++) {
|
||||
cin >> b[i].l >> b[i].r >> b[i].x;
|
||||
b[i].id = i;
|
||||
}
|
||||
sort(b + 1, b + 1 + q, cmp); // 按海平面上升高度排序
|
||||
cnt = 1;
|
||||
build(1, 1, n); // 构建线段树
|
||||
for (int i = 1; i <= q; i++) {
|
||||
while (cnt <= n && c[cnt].x <= b[i].x) {
|
||||
change(1, c[cnt].id, c[cnt].id); // 更新线段树
|
||||
cnt++;
|
||||
}
|
||||
ans[b[i].id] = ask(1, b[i].l, b[i].r); // 查询岛屿数量
|
||||
}
|
||||
for (int i = 1; i <= q; i++) {
|
||||
cout << ans[i] << endl; // 输出结果
|
||||
}
|
||||
return 0;
|
||||
}
|
53
Luogu/Luogu_U_458232.cpp
Normal file
53
Luogu/Luogu_U_458232.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define fp(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a += _d)
|
||||
#define fm(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a -= _d)
|
||||
#define fin(_a, _b) for(int ss = 1; ss <= _a; ss ++ ) cin >> _b[ss];
|
||||
#define fout(_a, _b, _c) for(int ss = 1; ss <= _a; ss ++ ) cout << _b[ss] << _c ;
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
2024/08/03
|
||||
Code-From-BunDragon126-At-VisualStudioCode
|
||||
AlignPixel*GiveSupport
|
||||
https://frederication.work/
|
||||
*/
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int t, n, m, k, a[N];
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
cin >> t;
|
||||
fp(ss, 1, t, 1)
|
||||
{
|
||||
cin >> n >> m ;
|
||||
if(m % 2 == 0) // 如果 m 是偶数且 n 为 0 ,输出 Yes。否则输出 No。
|
||||
{
|
||||
if(n == 0)
|
||||
{
|
||||
cout << "Yes" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "No" << endl;
|
||||
}
|
||||
}
|
||||
else // 如果 m 是奇数且 n 为正整数,输出 Yes 。否则输出 No。
|
||||
{
|
||||
if(n > 0)
|
||||
{
|
||||
cout << "Yes" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "No" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
58
Luogu/Luogu_U_458233.cpp
Normal file
58
Luogu/Luogu_U_458233.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define fp(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a += _d)
|
||||
#define fm(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a -= _d)
|
||||
#define fin(_a, _b) for(int ss = 1; ss <= _a; ss ++ ) cin >> _b[ss];
|
||||
#define fout(_a, _b, _c) for(int ss = 1; ss <= _a; ss ++ ) cout << _b[ss] << _c ;
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
<DATE>
|
||||
Code-From-BunDragon126-At-VisualStudioCode
|
||||
AlignPixel*GetSupport
|
||||
https://frederication.work/
|
||||
*/
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
string a, b;
|
||||
cin >> a >> b;
|
||||
char current_char = 'a';
|
||||
fp(i, 0, m - 1, 1)
|
||||
{
|
||||
bool found = false;
|
||||
fp(j, 0, n - 1, 1)
|
||||
{
|
||||
if (a[j] == '#')
|
||||
{
|
||||
a[j] = current_char;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
fp(j, 0, n - 1, 1)
|
||||
{
|
||||
if (b[j] == '#')
|
||||
{
|
||||
b[j] = current_char;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
current_char ++ ;
|
||||
if(current_char > 'z')
|
||||
{
|
||||
current_char = 'a';
|
||||
}
|
||||
}
|
||||
cout << a << endl;
|
||||
return 0;
|
||||
}
|
64
Luogu/Luogu_U_458234.cpp
Normal file
64
Luogu/Luogu_U_458234.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define fp(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a += _d)
|
||||
#define fm(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a -= _d)
|
||||
#define fin(_a, _b) for(int ss = 1; ss <= _a; ss ++ ) cin >> _b[ss];
|
||||
#define fout(_a, _b, _c) for(int ss = 1; ss <= _a; ss ++ ) cout << _b[ss] << _c ;
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
2024/08/03
|
||||
Code-From-BunDragon126-At-VisualStudioCode
|
||||
AlignPixel*GetSupport
|
||||
https://frederication.work/
|
||||
*/
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int calculateUniqueBloomTimes(vector<int>& times, int m, int offset = 0) {
|
||||
unordered_map<int, int> bloomCount;
|
||||
for (int t : times) {
|
||||
for (int i = 0; i < m; ++i) {
|
||||
bloomCount[t + offset + i]++;
|
||||
}
|
||||
}
|
||||
|
||||
int uniqueBloomTimes = 0;
|
||||
for (auto& entry : bloomCount) {
|
||||
if (entry.second == 1) {
|
||||
uniqueBloomTimes++;
|
||||
}
|
||||
}
|
||||
|
||||
return uniqueBloomTimes;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vector<int> t(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> t[i];
|
||||
}
|
||||
|
||||
int maxUniqueBloomTimes = calculateUniqueBloomTimes(t, m);
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
int originalTime = t[i];
|
||||
for (int newTime = 1; newTime <= *max_element(t.begin(), t.end()) + m; ++newTime) {
|
||||
if (newTime != originalTime) {
|
||||
t[i] = newTime;
|
||||
maxUniqueBloomTimes = max(maxUniqueBloomTimes, calculateUniqueBloomTimes(t, m));
|
||||
}
|
||||
}
|
||||
t[i] = originalTime;
|
||||
}
|
||||
|
||||
cout << maxUniqueBloomTimes << endl;
|
||||
return 0;
|
||||
}
|
96
Luogu/P1005 [NOIP2007 提高组] 矩阵取数游戏.cpp
Normal file
96
Luogu/P1005 [NOIP2007 提高组] 矩阵取数游戏.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MAXN = 85, Mod = 10000;
|
||||
int n, m;
|
||||
int ar[MAXN];
|
||||
|
||||
struct HP {
|
||||
int p[505], len;
|
||||
HP() {
|
||||
memset(p, 0, sizeof p);
|
||||
len = 0;
|
||||
}
|
||||
void print() {
|
||||
printf("%d", p[len]);
|
||||
for (int i = len - 1; i > 0; i--) {
|
||||
if (p[i] == 0) {
|
||||
printf("0000");
|
||||
continue;
|
||||
}
|
||||
for (int k = 10; k * p[i] < Mod; k *= 10)
|
||||
printf("0");
|
||||
printf("%d", p[i]);
|
||||
}
|
||||
}
|
||||
} f[MAXN][MAXN], base[MAXN], ans;
|
||||
|
||||
HP operator + (const HP &a, const HP &b) {
|
||||
HP c; c.len = max(a.len, b.len); int x = 0;
|
||||
for (int i = 1; i <= c.len; i++) {
|
||||
c.p[i] = a.p[i] + b.p[i] + x;
|
||||
x = c.p[i] / Mod;
|
||||
c.p[i] %= Mod;
|
||||
}
|
||||
if (x > 0)
|
||||
c.p[++c.len] = x;
|
||||
return c;
|
||||
} //高精+高精
|
||||
|
||||
HP operator * (const HP &a, const int &b) {
|
||||
HP c; c.len = a.len; int x = 0;
|
||||
for (int i = 1; i <= c.len; i++) {
|
||||
c.p[i] = a.p[i] * b + x;
|
||||
x = c.p[i] / Mod;
|
||||
c.p[i] %= Mod;
|
||||
}
|
||||
while (x > 0)
|
||||
c.p[++c.len] = x % Mod, x /= Mod;
|
||||
return c;
|
||||
} //高精*单精
|
||||
|
||||
HP max(const HP &a, const HP &b) {
|
||||
if (a.len > b.len)
|
||||
return a;
|
||||
else if (a.len < b.len)
|
||||
return b;
|
||||
for (int i = a.len; i > 0; i--)
|
||||
if (a.p[i] > b.p[i])
|
||||
return a;
|
||||
else if (a.p[i] < b.p[i])
|
||||
return b;
|
||||
return a;
|
||||
} //比较取最大值
|
||||
|
||||
void BaseTwo() {
|
||||
base[0].p[1] = 1, base[0].len = 1;
|
||||
for (int i = 1; i <= m + 2; i++){ //这里是m! m! m! 我TM写成n调了n年...
|
||||
base[i] = base[i - 1] * 2;
|
||||
}
|
||||
} //预处理出2的幂
|
||||
|
||||
int main(void) {
|
||||
scanf("%d%d", &n, &m);
|
||||
BaseTwo();
|
||||
while (n--) {
|
||||
memset(f, 0, sizeof f);
|
||||
for (int i = 1; i <= m; i++)
|
||||
scanf("%d", &ar[i]);
|
||||
for (int i = 1; i <= m; i++)
|
||||
for (int j = m; j >= i; j--) { //因为终值是小区间,DP自然就从大区间开始
|
||||
f[i][j] = max(f[i][j], f[i - 1][j] + base[m - j + i - 1] * ar[i - 1]);
|
||||
f[i][j] = max(f[i][j], f[i][j + 1] + base[m - j + i - 1] * ar[j + 1]);
|
||||
} //用结构体重载运算符写起来比较自然
|
||||
HP Max;
|
||||
for (int i = 1; i <= m; i++)
|
||||
Max = max(Max, f[i][i] + base[m] * ar[i]);
|
||||
ans = ans + Max; //记录到总答案中
|
||||
}
|
||||
ans.print(); //输出
|
||||
return 0;
|
||||
}
|
26
Luogu/P_1001_A_B_Problem.cpp
Normal file
26
Luogu/P_1001_A_B_Problem.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define fp(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a += _d)
|
||||
#define fm(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a -= _d)
|
||||
#define fin(_a, _b) for(int ss = 1; ss <= _a; ss ++ ) cin >> _b[ss];
|
||||
#define fout(_a, _b, _c) for(int ss = 1; ss <= _a; ss ++ ) cout << _b[ss] << _c ;
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
@author: BunDragon126
|
||||
@link: https://www.setbun.com/
|
||||
*/
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int a, b;
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
cin >> a >> b ;
|
||||
cout << a + b ;
|
||||
return 0;
|
||||
}
|
0
Luogu/P_1002_NOIP_2002_普及组_过河卒.cpp
Normal file
0
Luogu/P_1002_NOIP_2002_普及组_过河卒.cpp
Normal file
22
Luogu/P_1085_NOIP_2004_普及组_不高兴的津津.cpp
Normal file
22
Luogu/P_1085_NOIP_2004_普及组_不高兴的津津.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define fp(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a += _d)
|
||||
#define fm(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a -= _d)
|
||||
#define fin(_a, _b) for(int ss = 1; ss <= _a; ss ++ ) cin >> _b[ss];
|
||||
#define fout(_a, _b, _c) for(int ss = 1; ss <= _a; ss ++ ) cout << _b[ss] << _c ;
|
||||
using namespace std;
|
||||
|
||||
signed main()
|
||||
{
|
||||
int a, b, s, max = 0, i, day = 0;
|
||||
fp(i, 1, 8, 1)
|
||||
{
|
||||
cin >> a >> b;
|
||||
s = a + b;
|
||||
if ((s > max) && (s > 8))
|
||||
max = s, day = i;
|
||||
}
|
||||
cout << day;
|
||||
return 0;
|
||||
}
|
46
Luogu/P_1089_NOIP_2004_提高组_津津的储蓄计划.cpp
Normal file
46
Luogu/P_1089_NOIP_2004_提高组_津津的储蓄计划.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define fp(_a, _b, _c, _d) for (int _a = _b; _a <= _c; _a += _d)
|
||||
#define fm(_a, _b, _c, _d) for (int _a = _b; _a <= _c; _a -= _d)
|
||||
#define fin(_a, _b) for (int ss = 1; ss <= _a; ss++) cin >> _b[ss];
|
||||
#define fout(_a, _b, _c) for (int ss = 1; ss <= _a; ss++) cout << _b[ss] << _c;
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
@author: BunDragon126
|
||||
@link: https://www.setbun.com/
|
||||
*/
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int arr[N];
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
int money = 0;
|
||||
int l = 0;
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
money += 300;
|
||||
if (money < arr[i])
|
||||
{
|
||||
cout << -(i + 1) << endl;
|
||||
return 0;
|
||||
}
|
||||
money -= arr[i];
|
||||
int c = (money / 100) * 100;
|
||||
l += c;
|
||||
money -= c;
|
||||
}
|
||||
cout << money + l * 1.2 << endl;
|
||||
return 0;
|
||||
}
|
32
Luogu/P_1150_Peter_的烟.cpp
Normal file
32
Luogu/P_1150_Peter_的烟.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define fp(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a += _d)
|
||||
#define fm(_a, _b, _c, _d) for(int _a = _b; _a <= _c; _a -= _d)
|
||||
#define fin(_a, _b) for(int ss = 1; ss <= _a; ss ++ ) cin >> _b[ss];
|
||||
#define fout(_a, _b, _c) for(int ss = 1; ss <= _a; ss ++ ) cout << _b[ss] << _c ;
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
@author: BunDragon126
|
||||
@link: https://www.setbun.com/
|
||||
*/
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int n, k;
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
cin >> n >> k ;
|
||||
int cnt = 0;
|
||||
fp(i, 1, n, 1)
|
||||
{
|
||||
cnt ++ ;
|
||||
if(cnt % k == 0) n ++ ;
|
||||
}
|
||||
cout << cnt ;
|
||||
return 0;
|
||||
}
|
0
Luogu/P_1739_表达式括号匹配.cpp
Normal file
0
Luogu/P_1739_表达式括号匹配.cpp
Normal file
0
Luogu/U_458233_FLA_I_歌静河.cpp
Normal file
0
Luogu/U_458233_FLA_I_歌静河.cpp
Normal file
54
Luogu/[COCI 2023:2024 #2] Zatopljenje.cpp
Normal file
54
Luogu/[COCI 2023:2024 #2] Zatopljenje.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
const int N = 10005;
|
||||
|
||||
vector<int> h(N);
|
||||
|
||||
int f(const vector<int> &h, int l, int r, int x)
|
||||
{
|
||||
int cnt = 0;
|
||||
int start = l - 1;
|
||||
bool flag = false;
|
||||
|
||||
for (int i = start; i < r; ++i)
|
||||
{
|
||||
if (h[i] > x)
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
cnt++;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
int n, q;
|
||||
cin >> n >> q;
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
cin >> h[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < q; ++i)
|
||||
{
|
||||
int l, r, x;
|
||||
cin >> l >> r >> x;
|
||||
cout << f(h, l, r, x) << endl ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
10
Luogu/小鱼的航程.cpp
Normal file
10
Luogu/小鱼的航程.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int main(){
|
||||
long long x, n;
|
||||
cin >> x >> n;
|
||||
long long week;
|
||||
week = (x + n) / 7 * 2;
|
||||
cout << (n - week) * 250;
|
||||
return 0;
|
||||
}
|
36
Luogu/数字三角形2.cpp
Normal file
36
Luogu/数字三角形2.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
using namespace std;
|
||||
|
||||
const int N = 2e3 + 10;
|
||||
|
||||
int mp[N][N], d[N][N];
|
||||
|
||||
signed main()
|
||||
{
|
||||
int n;
|
||||
cin >> n ;
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
for(int j = 1; j <= i; ++ j)
|
||||
{
|
||||
cin >> mp[i][j] ;
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
for(int j = 1; j <= i; ++ j)
|
||||
{
|
||||
d[i][j] = max(d[i - 1][j - 1] + mp[i][j] % 100, d[i - 1][j] + mp[i][j] % 100);
|
||||
}
|
||||
}
|
||||
int ans = 0;
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
// cout << d[n][i] << " " ;
|
||||
ans = max(ans, d[n][i] % 100);
|
||||
}
|
||||
cout << ans ;
|
||||
return 0;
|
||||
}
|
85
Luogu/素数环【洛谷版UVa】.cpp
Normal file
85
Luogu/素数环【洛谷版UVa】.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int MAXN = 16;
|
||||
int n;
|
||||
int arr[MAXN];
|
||||
bool vis[MAXN];
|
||||
|
||||
// 判断一个数是否为素数
|
||||
bool check(int num)
|
||||
{
|
||||
if (num < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 2; i * i <= num; i++)
|
||||
{
|
||||
if (num % i == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 回溯
|
||||
// cur表示当前位置
|
||||
void back(int cur)
|
||||
{
|
||||
if (cur == n) // 检查最后一个数字和第一个数字之和是否为素数
|
||||
{
|
||||
if (check(arr[0] + arr[n - 1]))
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (int i = 2; i <= n; i++)
|
||||
{
|
||||
if (!vis[i] && check(arr[cur - 1] + i))
|
||||
{
|
||||
vis[i] = true;
|
||||
arr[cur] = i;
|
||||
back(cur + 1);
|
||||
vis[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int idx = 1;
|
||||
while(n != EOF)
|
||||
{
|
||||
cin >> n;
|
||||
cout << "Case " << idx++ << ":" << endl;
|
||||
memset(vis, false, sizeof(vis));
|
||||
vis[1] = true;
|
||||
arr[0] = 1;
|
||||
back(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
以下题解为后期由本人添加
|
||||
题目分析:
|
||||
题目要求将整数 1 到 n 组成一个环,使得相邻的两个整数之和均为素数。
|
||||
我们需要找到所有满足条件的素数环,并按照要求输出。
|
||||
由于 n 的值不超过 16,我们可以使用回溯法来尝试所有可能的组合。
|
||||
代码解释:
|
||||
check函数用于判断一个数是否为素数。
|
||||
back函数是回溯函数,用于尝试放置数字到环中。
|
||||
在back函数中,首先判断是否已经放置了 n 个数字。如果是,则检查最后一个数字和第一个数字之和是否为素数。如果是素数,则输出这个环。
|
||||
然后,从数字 2 到 n 依次尝试将每个数字放在环的下一个位置。如果该数字没有被使用过,并且与前一个数字之和为素数,就将其放在环的下一个位置,并标记为已使用,然后继续递归放置下一个数字。
|
||||
如果放置过程中出现相邻两个数字之和不是素数的情况,就回溯到上一个数字,重新选择下一个数字。
|
||||
在main函数中,读取输入的 n,初始化标记数组和环的第一个数字,然后调用back函数从数字 1 开始回溯。
|
||||
时间复杂度和空间复杂度:
|
||||
时间复杂度:由于需要尝试所有可能的组合,时间复杂度为 O(n!),其中 n 是输入的数字个数。
|
||||
空间复杂度:主要是使用了标记数组和环数组,空间复杂度为 O(n)。
|
||||
*/
|
48
Luogu/螺旋矩阵.cpp
Normal file
48
Luogu/螺旋矩阵.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
using namespace std;
|
||||
signed main()
|
||||
{
|
||||
int n, x, y;
|
||||
cin >> n >> x >> y ;
|
||||
int rx = 1, num = y; // rx为模拟到的行数,num为目前加到的数,也是最终输出的结果
|
||||
int up = 1, down = n, zuo = 1, you = n; // x、y在下一次绕圈时上下左右的边界值(可以理解为将要被蛇形填数的一圈的边界)
|
||||
bool fx = true; // 方向(true往下,false往上)
|
||||
while (rx != x) // 一直模拟到刚好到达
|
||||
{
|
||||
if (fx) // 特判
|
||||
{
|
||||
if (you == y) // 如果是往下走直线
|
||||
{
|
||||
num += x - rx; // 加上最后的数
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (zuo == y) // 如果是向上走直线
|
||||
{
|
||||
num += rx - x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fx) // 普通情况,如果向下走
|
||||
{
|
||||
num += (you - y + 1) * 2 + down - rx - 2; // 绕一圈
|
||||
rx = down; // 更新所在的行
|
||||
you -- ; // 右边界往回退一格
|
||||
up ++ ; // 上边界往回退一格
|
||||
}
|
||||
else // 往上走
|
||||
{
|
||||
num += (y - zuo + 1) * 2 + rx - up - 2; // 绕一圈
|
||||
rx = up; // 更新行
|
||||
zuo ++ ; // 左边界向内
|
||||
down -- ; // 下边界向内
|
||||
}
|
||||
fx = !fx; // 方向调转
|
||||
}
|
||||
cout << num ;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user