rewrite ^/(?!.well-known)(.*)$ /index.php?/$1 last;
放到 /usr/local/nginx/conf/rewrite 中
https://github.com/qkqpttgf/OneManager-php
ps:怕我忘记所以记一下
rewrite ^/(?!.well-known)(.*)$ /index.php?/$1 last;
放到 /usr/local/nginx/conf/rewrite 中
https://github.com/qkqpttgf/OneManager-php
ps:怕我忘记所以记一下
url: https://www.luogu.com.cn/problem/P2004
tag:
前缀和
思路:
先求前缀和,然后遍历右下端点,求出每个对应的子矩阵的总和,判断是否大于res,如果大的话就更新res和坐标x,y。最后输出x和y即可。
ps:这道题很简单,本来不应该传博客的,但是觉得自己写的好优美,忍不住传一下,以后偶尔可以翻出来看看。真的好优美感觉。
代码:
#include <iostream>
using namespace std;
const int N = 1010;
long long p[N][N];
int n, m , c;
int main()
{
cin >> n >> m >> c;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
{
cin >> p[i][j];
p[i][j] += p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1];
}
long long res = 0, x, y;
for (int i = c; i <= n; i ++)
for (int j = c; j <= m; j ++)
{
long long tmp = p[i][j] - p[i - c][j] - p[i][j - c] + p[i - c][j - c];
if (tmp > res)
{
res = tmp;
x = i - c + 1;
y = j - c + 1;
}
}
cout << x << ' ' << y;
return 0;
}
小U计划进行一场从地点A到地点B的徒步旅行,旅行总共需要 M
天。为了在旅途中确保安全,小U每天都需要消耗一份食物。在路程中,小U会经过一些补给站,这些补给站分布在不同的天数上,且每个补给站的食物价格各不相同。
小U需要在这些补给站中购买食物,以确保每天都有足够的食物。现在她想知道,如何规划在不同补给站的购买策略,以使她能够花费最少的钱顺利完成这次旅行。
M
:总路程所需的天数。N
:路上补给站的数量。p
:每个补给站的描述,包含两个数字 A
和 B
,表示第 A
天有一个补给站,并且该站每份食物的价格为 B
元。保证第0天一定有一个补给站,并且补给站是按顺序出现的。
样例1:
输入:m = 5 ,n = 4 ,p = [[0, 2], [1, 3], [2, 1], [3, 2]]
输出:7
样例2:
输入:m = 6 ,n = 5 ,p = [[0, 1], [1, 5], [2, 2], [3, 4], [5, 1]]
输出:6
样例3:
输入:m = 4 ,n = 3 ,p = [[0, 3], [2, 2], [3, 1]]
输出:9
代码:
int solution(int m, int n, std::vector<std::vector<int>> p) {
// 在末尾添加一个虚拟站点表示终点,价格设为0(方便处理,但不会实际购买)
p.push_back({m, 0});
int totalCost = 0;
int currentIndex = 0; // 当前站点索引
while (currentIndex < p.size() - 1) { // 最后一个虚拟站点不作为实际购买点
int currentDay = p[currentIndex][0];
int currentPrice = p[currentIndex][1];
int nextIndex = currentIndex + 1;
// 找到下一个比当前站价格低的站点或者终点
while (nextIndex < p.size() && p[nextIndex][1] >= currentPrice) {
nextIndex++;
}
// 如果未找到更便宜的,nextIndex 会指向虚拟终点站
if (nextIndex == p.size()) {
nextIndex = p.size() - 1;
}
int nextDay = p[nextIndex][0];
// 计算从当前站到目标站之间需要的天数差
int daysNeeded = nextDay - currentDay;
// 在当前站购买足够的食物以覆盖到下一个更便宜的站或终点
totalCost += daysNeeded * currentPrice;
// 将当前站点移动到找到的更便宜的站点
currentIndex = nextIndex;
}
return totalCost;
}
tag:
贪心
思路:
用贪心的策略,每次都找一个花费比当前补给站少的点,然后买刚好到那个补给站的食物。然后将当前的位置更新到那个补给站,直到到达终点。
url: https://www.luogu.com.cn/problem/P4343
tag:
二分,模拟
思路:
思路比较简单,根据题目可以知道当n越小时切出来的题目数量越多,根据这个来二分。分别二分出一个最小值和一个最大值。这道题是细节比较 恶心(bushi 多,需要注意的点比较多。第一个是二分的范围,题目只有一个xi的范围是1e-9到1e9,经测试,r开到1e9范围比较小,看了题解之后发现需要开到1e18.然后这里就有一个问题,因为超过了1e9所以变量不能放到main()函数中,只能放到外面当全局变量。然后如果是mid要用long long类型,记得check函数的函数签名中变量的类型也要是long long。第二个细节是l要从1开始,不能从0开始。第三个细节是,题目没有保证说如果其中一个答案比如最小值存在,另外一个答案就会存在,所以对于最小值和最大值都要进行验证。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
long long n, k, l ,r;
long long p[N];
long long check (long long x)
{
long long sum = 0, cnt = 0;
for (int i = 0; i < n; i ++)
{
if (p[i] > 0) sum += p[i];
else sum = max((long long)0, sum + p[i]);
if (sum >= x)
{
sum = 0;
cnt ++;
}
}
return cnt;
}
int main()
{
scanf("%lld%lld", &n, &k);
for (int i = 0; i < n; i ++) scanf("%lld", &p[i]);
l = 1, r = 1e18;
while (l < r)
{
long long mid = (l + r) >> 1;
if (check(mid) <= k) r = mid;
else l = mid + 1;
}
long long tmp;
if (check(l) != k)
{
cout << -1 ;
return 0;
}
else tmp = l;
l = 1, r = 1e18;
while (l < r)
{
long long mid = (l + r + 1) >> 1;
if (check(mid) >= k) l = mid;
else r = mid - 1;
}
if (check(l) != k)
{
cout << -1 ;
return 0;
}
else cout << tmp << ' ' << l;
return 0;
}
url: https://www.luogu.com.cn/problem/P1115
tag:
最大子数列,Kadane 算法,动态规划
思路:
使用动态规划得方法来求解,用两个变量currentSum,和maxSum,分别来维护以当前位置结尾的最大子段和以及全局的最大子段和。状态转移分别是currentSum = max(a, currentSum + a), maxSum = max(maxSum, currentSum).最后输出maxSum即可。细节:一开始可以先定义为最小值-0x3f3f3f3f这样可以避免漏掉负数,以及因为要求和所以最好开long long避免爆int。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int main()
{
scanf("%d", &n);
long long currentSum = -0x3f3f3f3f, maxSum = -0x3f3f3f3f;
for (int i = 0; i < n; i ++)
{
long long a;
scanf("%lld", &a);
currentSum = max(a, currentSum + a);
maxSum = max(maxSum, currentSum);
}
cout << maxSum << endl;
return 0;
}