
洛谷
erci_fc2336
我今天一定努力੭ ᐕ)੭*⁾⁾
展开
-
P2430 严酷的训练
传送门思路:求最大奖励值就可以转换成费用为 p[ i ].a,价值为 p[ i ].b ,求最大价值的问题。这道题就转化成了在一定大小的背包内(即规定时间内)可以装下的最大价值的物品, 变成一道01背包的问题。 WKY花费时间的倍数×老王做题时间 = WKY做题用时。accode:#include <bits/stdc++.h>using namespace std;#define max(a,b) (a)>(b) ? (a) : (b);typedef long lon原创 2022-03-12 09:00:05 · 260 阅读 · 0 评论 -
P3370 字符串哈希
传送门accode:#include <bits/stdc++.h>using namespace std;typedef unsigned long long ull;const ull seed = 13131313131;const int maxn = 1e6 + 10;ull a[maxn];char s[maxn];int n, ans = 1;int prime = 2333317;ull mod = 212370440130137957ll;ull ha原创 2022-03-12 08:44:16 · 158 阅读 · 0 评论 -
洛谷P3879 [TJOI2010] 阅读理解
题意:英语老师留了 N 篇阅读理解作业,但是每篇英文短文都有很多生词需要查字典,为了节约时间,现在要做个统计,算一算某些生词都在哪几篇短文中出现过。思路:建立一个string映射到set的映射#include <bits/stdc++.h>using namespace std;map<string,set<int> > mp;set<int>::iterator it;int main(){ ios::sync_with_stdio原创 2022-03-10 09:12:54 · 155 阅读 · 0 评论 -
洛谷P1308 [NOIP2011 普及组] 统计单词数
这道题坑点好多aaaT^T,特来整理一下过程中遇到的问题。题目传送站点~题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数。 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给定的文章中出现的次数和第一次出现的位置。注意:匹配单词时,不区分大小写,但要求完全匹配,即给定单词必须与文章中的某一独立单词在不区分大小写的情况下完全相同(参见样例 1),如果给定单词仅是文章中某一单词的一部分则不算匹配(参见样例原创 2021-03-23 23:02:45 · 750 阅读 · 0 评论 -
洛谷P5490 扫描线
扫描线的学习参考了以下博客:线段树+扫描线(有关扫描线的理解)扫描线做题:洛谷P5490 扫描线#include <bits/stdc++.h>#define ios std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);using namespace std;typedef long long ll;const int maxn = 1e6 + 10;int mark[maxn<<2];//记录某个区原创 2022-02-25 19:49:23 · 336 阅读 · 0 评论 -
P6477 [NOI Online #2 提高组] 子序列问题
参考链接:NOI Online2 提高组 子序列问题在做hdu第7场的1012题时想到的类似题目,用线段树去解决区间平方和问题,但是那题我还没调好我的代码。accode:#define maxn 1000010#define mod 1000000007#define ll long longint n, a[maxn], f[maxn], last[maxn];int Next[maxn];ll tr1[maxn], tr2[maxn];ll change(int x,int y)原创 2022-03-03 08:14:16 · 154 阅读 · 0 评论 -
caioj 1172 单调队列
题意:给定一个n个数的数列,从左至右输出每个长度为m的数列段内的最大数。如果按照常规方法,我们在求 f[ i ] 即 i ~ i + m - 1 区间内的最值时,要把区间内的所有数都访问一遍,时间复杂度约为O(nm)。上一种算法有一个地方是重复比较了,就是在找当前的f(i)的时候,i 的前面k-1个数其它在算f( i - 1)的时候我们就比较过了。选择保存上一次的结果,也就是i 的前k-1个数中的最大值,这就要用到单调递减队列。使用单调队列就涉及到去头和删尾:1、队列的头一定是在一段时间前就加入了原创 2022-03-03 08:11:02 · 111 阅读 · 0 评论 -
洛谷P3374 (线段树学习1)
#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>#include <math.h>#include <vector>#include <queue>#include <stack>using namespace std;typedef long long ll;const int maxn原创 2022-02-25 19:51:53 · 129 阅读 · 0 评论 -
最大子矩阵和
最大子矩阵和动态规划,计算最大子矩阵和,可以将该问题转化为计算最大子段和问题,是一个经典的动态规划问题。不同点在于它是要求子“矩阵”和,长宽未知要遍历——即,起点行和终点行未知要遍历,起点列和终点列未知要遍历。s数组是用来记录起点行到终点行的每一竖条的数值和的,dp[k]是用来记录不同的子矩阵和的(需要相邻竖条相加),maxx是用来保存最大字段和的。#include <stdio.h>#include <string.h>#include <iostream&g原创 2022-02-25 19:36:56 · 301 阅读 · 0 评论 -
洛谷P3368 (线段树学习2)
#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>#include <math.h>using namespace std;typedef long long ll;const int maxn = 3e6 + 10;//注意根节点的大小范围 #define in(a) a = read()#define REP(i,k,n) f原创 2022-02-25 19:50:45 · 147 阅读 · 2 评论 -
洛谷P1908 逆序对
归并排序#include <stdio.h>#include <string.h>#include <iostream>#include <vector>#include <algorithm> using namespace std;typedef long long ll;const int maxn = 5e5 + 10;int a[maxn];ll ans = 0;#define in(c) c = read()#d原创 2022-02-25 19:54:25 · 213 阅读 · 0 评论 -
洛谷P1010
P1010幂次方#include <stdio.h>#include <iostream>using namespace std;int main(){ int n, m, i, j, k, flag; int map[100] = {0}; cin>>n; m = n; i = 1; while(m > 0) { map[i] = m % 2; i ++; m /= 2; } i --; flag = i; //2*原创 2020-11-16 16:22:42 · 138 阅读 · 0 评论 -
枚举 洛谷P2105 K皇后
枚举 洛谷P2105 K皇后传送站点用二维数组存储会爆内存,看了题解,特来补题。改用枚举,先枚举行再枚举每个皇后进行判断知道一条直线的斜率,直线上的一个点及另一点的横坐标,可以求出该点纵坐标 会被皇后左对角线斜着攻击的点的横纵坐标之差等于皇后横纵坐标之差 y[ j ] - x[ j ] = y1 - i; 会被皇后右对角线斜着攻击的点的横纵坐标之和等于皇后横纵坐标之和 y[ j ] + x[ j ] = y2 + i;用以上两个公式表示每个会被攻击到的点的纵坐标#include <原创 2021-03-24 17:22:55 · 163 阅读 · 0 评论