-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.json
1 lines (1 loc) · 62.4 KB
/
content.json
1
{"meta":{"title":"尔玉博客","subtitle":"","description":"","author":"尔玉","url":"https://sealofyou.github.io","root":"/"},"pages":[{"title":"友情链接","date":"2021-12-12T10:39:11.000Z","updated":"2021-12-12T10:44:23.202Z","comments":true,"path":"link/index.html","permalink":"https://sealofyou.github.io/link/index.html","excerpt":"","text":""},{"title":"分类","date":"2021-12-12T10:35:30.000Z","updated":"2023-03-19T03:29:15.798Z","comments":true,"path":"categories/index.html","permalink":"https://sealofyou.github.io/categories/index.html","excerpt":"","text":""},{"title":"标题","date":"2021-12-12T10:33:44.000Z","updated":"2021-12-12T10:44:02.292Z","comments":true,"path":"tags/index.html","permalink":"https://sealofyou.github.io/tags/index.html","excerpt":"","text":""}],"posts":[{"title":"最短路","slug":"最短路","date":"2023-04-25T09:10:22.000Z","updated":"2023-04-25T10:02:29.960Z","comments":true,"path":"2023/04/25/最短路/","link":"","permalink":"https://sealofyou.github.io/2023/04/25/%E6%9C%80%E7%9F%AD%E8%B7%AF/","excerpt":"","text":"最短路 总结 image-20230412204030858 Dijkstra(朴素) 思路: n次循环,每次找到点集外最近的点 更新所有点最近距离 AcWing 849. Dijkstra求最短路 I 1234567891011121314151617181920212223242526272829303132333435363738394041#include<bits/stdc++.h>using namespace std;const int N=510;int g[N][N],d[N],st[N];int n,m;int dj(){ memset(d,0x3f,sizeof d); d[1]=0; for(int i=1;i<=n;i++) { int t=-1; //找到集合外最小距离 for(int j=1;j<=n;j++) if(!st[j] && (t==-1 || d[t]>d[j]))t=j; st[t]=1; //更新所有点 for(int j=1;j<=n;j++) d[j]=min(d[j],d[t]+g[t][j]); } if(d[n]==0x3f3f3f3f)return -1; else return d[n];}int main(){ memset(g,0x3f,sizeof g); cin>>n>>m; for(int i=1;i<=m;i++) { int a,b,c; cin>>a>>b>>c; g[a][b]=min(g[a][b],c); } int t=dj(); cout<<t; return 0;} Dijkstra(堆优化) 思路: n次循环,每次找到点集外最近的点(小根堆实现) 更新所有点最近距离 AcWing 850. Dijkstra求最短路 II 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556#include<bits/stdc++.h>using namespace std;const int N = 1e6 + 10, M = N * 2;typedef pair<int, int> PII;int h[N], e[N], ne[N], w[N], idx;int dist[N];bool st[N];int n, m;void add(int a, int b, int c){ e[idx] = b; w[idx] = c; ne[idx] = h[a]; h[a] = idx ++;}int dj(){ memset(dist, 0x3f, sizeof dist); dist[1] = 0; priority_queue<PII, vector<PII>, greater<PII>> heap; heap.push({0,1}); while(heap.size()) { PII t = heap.top(); heap.pop(); int ver = t.second, distance = t.first; if(st[ver])continue; st[ver] = 1; for(int i = h[ver]; i != -1; i = ne[i]) { int j = e[i]; if(dist[j] > distance + w[i]) { dist[j] = distance + w[i]; heap.push({dist[j], j}); } } } if(dist[n] == 0x3f3f3f3f)return -1; return dist[n];}int main(){ memset(h, -1, sizeof h); cin >> n >> m; while(m --) { int a, b, c; cin >> a >> b >> c; add(a, b, c); } int t = dj(); cout << t <<endl; return 0;} bellman-ford算法 思路 n次循环,循环所有边。 循环所有边时更新所有边 AcWing 853. 有边数限制的最短路 12345678910111213141516171819202122232425262728293031323334#include<bits/stdc++.h>using namespace std;const int N = 510, M = 1e4 + 10;struct { int a, b, w;} h[M];int dist[N],backcopy[N];int n, m ,k;void bf(){ memset(dist, 0x3f, sizeof dist); dist[1] = 0; for(int i = 1; i <= k ; i ++) { memcpy(backcopy, dist, sizeof backcopy); for(int j = 1; j <= m; j ++) { dist[h[j].b] = min(dist[h[j].b], backcopy[h[j].a] + h[j].w); } } if(dist[n] > 0x3f3f3f3f / 2)puts("impossible"); else cout << dist[n]; return;}int main(){ cin >> n >> m >> k; for(int i = 1; i <= m; i ++) { cin >> h[i].a >> h[i].b >> h[i].w; } bf(); return 0;} spfa算法 思路 12345678queue <- 初点while(queue不空) t <- q.front(); q.pop(); // 更新t的所有出边 t -w-> b (如果b变小了)queue <- b AcWing 851. spfa求最短路 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#include<bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int h[N], e[N], ne[N], w[N], idx;int dist[N];bool st[N];int n,m;void add(int a, int b, int c){ e[idx] = b;w[idx] = c;ne[idx] = h[a];h[a] = idx ++;}int spfa(){ memset(dist, 0x3f, sizeof dist); dist[1] = 0; queue<int> q; q.push(1); st[1] = true; while(q.size()) { int t = q.front(); q.pop(); st[t] = false; for(int i = h[t]; i != -1; i = ne[i]) { int j = e[i]; if(dist[j] > dist[t] + w[i]) { dist[j] = dist[t] + w[i]; if(!st[t]) { st[j] = true; q.push(j); } } } } return dist[n];}int main(){ memset(h, -1, sizeof h); cin >> n >> m; for(int i = 1; i <= m; i ++) { int a, b, c; cin >> a >> b >> c; add(a, b, c); } int t = spfa(); if(t > 0x3f3f3f3f / 2)cout << "impossible"; else cout << t; return 0;} Floyd 思路 1234for(k 1~n) for(i 1~n) for(j 1~n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]); AcWing 854. Floyd求最短路 12345678910111213141516171819202122232425262728293031323334#include<bits/stdc++.h>using namespace std;const int N = 210;int g[N][N];int n, m, t;void floyd(){ for(int k = 1; k <= n; k ++) for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);}int main(){ cin >> n >> m >> t; memset(g, 0x3f, sizeof g); for(int i = 1; i <= n; i ++)g[i][i] = 0; for(int i = 1; i <= m; i ++) { int a, b, c; cin >> a >> b >> c; g[a][b] = min(g[a][b], c); } floyd(); while(t --) { int a, b; cin >> a >> b; if(g[a][b] > 1e9 / 2)puts("impossible"); else cout << g[a][b] << endl; }}","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"图论","slug":"图论","permalink":"https://sealofyou.github.io/tags/%E5%9B%BE%E8%AE%BA/"},{"name":"最短路","slug":"最短路","permalink":"https://sealofyou.github.io/tags/%E6%9C%80%E7%9F%AD%E8%B7%AF/"}]},{"title":"slidev","slug":"slidev","date":"2023-04-19T06:46:23.000Z","updated":"2023-04-19T07:54:52.370Z","comments":true,"path":"2023/04/19/slidev/","link":"","permalink":"https://sealofyou.github.io/2023/04/19/slidev/","excerpt":"","text":"Slidev 官网 介于官网有相应文档,一些东西不会很详细,主打的是个人使用的坑之类的。 安装使用 本地安装 1. 安装node.js 略 2.安装Slidev 使用 NPM: 1$ npm init slidev@latest 使用Yarn: 1$ yarn create slidev 跟随命令行的提示,它将自动为你打开幻灯片,网址是 http://localhost:3030/。 同时包含了一些基本配置和简单的 demo,为你说明如何开始使用 Slidev。 构建单网页应用 因为build完之后可以在 dist 目录下将你的幻灯片生成静态 HTML 文件。 所以怎么放都可以 硬放到服务器上 完成PPT 执行命令slidev --base 你需要部署到的位置 粘(传)到服务器上(dist目录内所有),配置nginx。 访问相应IP或域名 例子 12345slidev --base /slidev配置完nginx后访问: IP/slidev 域名/slidev (配置域名) 导出(PDF) 安装 playwright-chromium: 1$ npm i -D playwright-chromium 接着,使用如下命令即可将你的幻灯片导出为 PDF: 1$ slidev export 稍作等待,即可在 ./slides-export.pdf 路径下看到你幻灯片的 PDF 文件。 如果你想要导出使用暗色主题的幻灯片,请使用 --dark 选项: 1$ slidev export --dark 导出点击步骤 默认情况下,Slidev 会将每张幻灯片导出为 1 页,并忽略点击动画。如果你想将多个步骤的幻灯片,分解为多个页面,请使用 --with-clicks 选项。 1$ slidev export --with-clicks PNGs 当为命令传入 --format png 选项时,Slidev 会将每张幻灯片导出为 PNG 图片格式。 1$ slidev export --format png VSCode插件推荐:slidev slidev插件网址 优点: 代码中显示这是 第几页 幻灯片 侧边栏上半:可以显示每一页幻灯片名字及快速转到某一页幻灯片 侧边栏下半:slidev打开后可以实时显示幻灯片(VSCode内,不用再开浏览器) Markdown 语法 分隔符 使用---来分割幻灯片。 两行 分隔符上下间隔两行,不然认不出来直接寄 扉页和布局 扉页尽量贴着前后的--- 123---layout: cover--- yaml格式的对象,语法如下: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364---# 主题id 或 主题包名称# 了解更多:https://sli.dev/themes/use.htmltheme: 'default'# 幻灯片的总标题,如果没有指定,那么将以第一张拥有标题的幻灯片的标题作为总标题title: 'Slidev'# titleTemplate for the webpage, `%s` will be replaced by the page's titletitleTemplate: '%s - Slidev'# information for your slides, can be a markdown stringinfo: false# 在单页(SPA)构建中启用 pdf 下载,也可以指定一个自定义 urldownload: false# 要导出文件的文件名称exportFilename: 'slidev-exported.pdf'# 语法高亮设置,可以使用 'prism' 或 'shiki' 方案highlighter: 'prism'# 在代码块中显示行号lineNumbers: false# 启用 monaco 编辑器,可以是 boolean,'dev' 或者 'build'monaco: 'dev'# 使用 vite-plugin-remote-assets 在本地下载远程资源,可以是 boolean,'dev' 或者 'build'remoteAssets: false# 控制幻灯片中的文本是否可以选择selectable: true# 启用幻灯片录制,可以是 boolean,'dev' 或者 'build'record: 'dev'# 幻灯片的配色方案,可以使用 'auto','light' 或者 'dark'colorSchema: 'auto'# vue-router 模式,可以使用 'history' 或 'hash' 模式routerMode: 'history'# 幻灯片的长宽比aspectRatio: '16/9'# canvas 的真实宽度,单位为 pxcanvasWidth: 980# 用于主题定制,会将属性 `x` 注入根样式 `--slidev-theme-x`themeConfig: primary: '#5d8392'# favicon 可以是本地文件路径,也可以是一个 URLfavicon: 'https://cdn.jsdelivr.net/gh/slidevjs/slidev/assets/favicon.png'# 用于渲染图表的 PlantUML 服务器的 URLplantUmlServer: 'https://www.plantuml.com/plantuml'# 字体将从 Google 字体自动导入# 了解更多:https://sli.dev/custom/fontsfonts: sans: 'Roboto' serif: 'Roboto Slab' mono: 'Fira Code'# 为所有幻灯片添加默认的 frontmatterdefaults: layout: 'default' # ...# 绘制选项# 了解更多:https://sli.dev/guide/drawing.htmldrawings: enabled: true persist: false presenterOnly: false syncAll: true--- 布局很常用,下单列。 代码块 基础同Markdown 通过在语言名后写大括号的形式来指定特定行高亮{} 注:行号从1开始。 内联样式 你可以在 Markdown 中直接使用 <style> 标签来覆盖当前幻灯片的样式。 Slidev支持windicss的原子化写法和指令集 例如@apply 静态资源 和编写 Markdown 的方式一样,你可以使用本地或远程的 URL 的图片。 远程资源会缓存 本地资源请放到public文件夹","categories":[{"name":"slidev","slug":"slidev","permalink":"https://sealofyou.github.io/categories/slidev/"}],"tags":[{"name":"slidev","slug":"slidev","permalink":"https://sealofyou.github.io/tags/slidev/"}]},{"title":"hexo使用","slug":"hexo使用","date":"2023-04-12T12:18:24.000Z","updated":"2023-04-12T12:19:05.048Z","comments":true,"path":"2023/04/12/hexo使用/","link":"","permalink":"https://sealofyou.github.io/2023/04/12/hexo%E4%BD%BF%E7%94%A8/","excerpt":"","text":"hexo使用 新建文章:hexo n 文章名 清除文章:hexo clean 生成:hexo g 更新页面:hexo d或hexo deploy 生成+更新页面:hexo g -d 端口部署:hexo s -p 555 hexo相关(可能) git Bash here Typora打开文件: start 文件名 部署 github、gitee部署省略 服务器部署(没用自动部署,github钩子那种) git pull到服务器上。 改nginx使其可以被展示出来。(详见占位) 缺点: 每次更新需要去服务器上 'git pull' 和 sudo nginx -s reload 改善:可以写个shell脚本试试","categories":[{"name":"hexo","slug":"hexo","permalink":"https://sealofyou.github.io/categories/hexo/"}],"tags":[{"name":"hexo","slug":"hexo","permalink":"https://sealofyou.github.io/tags/hexo/"}]},{"title":"基础图论","slug":"基础图论","date":"2023-04-12T12:02:27.000Z","updated":"2023-04-25T10:02:56.855Z","comments":true,"path":"2023/04/12/基础图论/","link":"","permalink":"https://sealofyou.github.io/2023/04/12/%E5%9F%BA%E7%A1%80%E5%9B%BE%E8%AE%BA/","excerpt":"","text":"基础图论 树与图的存储和遍历 树与图的 存储 因为树是无环连通图,所以可以只看图。而图分为无向图和有向图,无向图每条边可以表示为两条有向边,所以可以只看有向图。 1.邻接表 用多个单链表构成的邻接表存储这个点指向的边(即出度),多用于稀疏图(n== m)。 12345678910const int N=100010,M=N*2;int h[N],e[M],ne[M],idx;void add(int a,int b){ e[idx]=b;ne[idx]=h[a],h[a]=idx++;}int main(){ memset(h,-1,sizeof h);} 2.邻接矩阵 用一个二维数组存储点边的关系,多用于稠密图(n == m^2)。 g[a] [b]指从a指向b的边,为0即为无边,非0即为有边(值可以存成权值等) 缺点:不能存重边。 树与图的 遍历 DFS 同普通DFS AcWing 846. 树的重心 1234567891011121314151617181920212223242526272829303132333435363738394041#include<bits/stdc++.h>using namespace std;const int N=100010,M=N*2;int h[N],e[M],ne[M],idx;int ans=N,st[N];int n;void add(int a,int b){ e[idx]=b;ne[idx]=h[a];h[a]=idx++;}int dfs(int u){ st[u]=1; int sum=1,res=0; for(int i=h[u];i!=-1;i=ne[i]) { int j=e[i]; if(!st[j]) { int s=dfs(j); res=max(res,s); sum+=s; } } res=max(res,n-sum); ans=min(ans,res); return sum;}int main(){ cin>>n; memset(h,-1,sizeof h); for(int i=1;i<n;i++) { int a,b;cin>>a>>b; add(a,b);add(b,a); } dfs(1); cout<<ans; return 0;} BFS 同普通BFS AcWing 847. 图中点的层次 1234567891011121314151617181920212223242526272829303132333435363738394041424344#include<bits/stdc++.h>using namespace std;const int N=100010,M=N*2;int h[N],e[M],ne[M],idx;int d[N];int n,m;void add(int a,int b){ e[idx]=b;ne[idx]=h[a];h[a]=idx++;}int bfs(){ queue<int> q; q.push(1); memset(d,-1,sizeof d); d[1]=0; while(q.size()) { int t=q.front(); q.pop(); for(int i=h[t];i!=-1;i=ne[i]) { int j=e[i]; if(d[j]!=-1)continue; d[j]=d[t]+1; q.push(j); } } return d[n];}int main(){ cin>>n>>m; memset(h,-1,sizeof h); for(int i=1;i<=m;i++) { int a,b;cin>>a>>b; add(a,b); } cout<<bfs(); return 0;} 常用算法 拓扑排序 有向无环图。(bfs) 做法 类比多元bfs 将所有入度为0的点放入queue。 遍历queue每个点,将点所有出度对应的点入读-1。 将入读为0的点再放到queue中。 最后判断所有的点入度是否都是0。 AcWing 848. 有向图的拓扑序列 12345678910111213141516171819202122232425262728293031323334353637383940414243444546#include<bits/stdc++.h>using namespace std;const int N=100010;int h[N],e[N],ne[N],idx;int d[N],c[N],num;int n,m;queue<int> q;void add(int a,int b){ e[idx]=b;ne[idx]=h[a];h[a]=idx++;}void bfs(){ while(q.size()) { int t=q.front(); q.pop(); c[++num]=t; for(int i=h[t];i!=-1;i=ne[i]) { int j=e[i]; d[j]--; if(!d[j])q.push(j); } }}int main(){ cin>>n>>m; for(int i=1;i<=n;i++)h[i]=-1; for(int i=1;i<=m;i++) { int a,b;cin>>a>>b; add(a,b); d[b]++; } for(int i=1;i<=n;i++)if(!d[i])q.push(i); bfs(); if(num!=n)cout<<"-1"; else { for(int i=1;i<=n;i++)cout<<c[i]<<' '; }} 最短路 详见最短路。 总结 image-20230412204030858 Dijkstra(朴素) 思路: n次循环,每次找到点集外最近的点 更新所有点最近距离 Dijkstra(堆优化) 思路: n次循环,每次找到点集外最近的点(小根堆实现) 更新所有点最近距离 bellman-ford算法 思路: n次循环,循环所有边。 循环所有边时更新所有边 spfa算法 思路: 123456789queue <- 初点while(queue不空) t <- q.front(); q.pop(); // 更新t的所有出边 t -w-> b (如果b变小了)queue <- b Floyd 思路 1234for(k 1~n) for(i 1~n) for(j 1~n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]); 最小生成树 Prim Kruskal 其它 染色法判定二分图 匈牙利算法","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"图论","slug":"图论","permalink":"https://sealofyou.github.io/tags/%E5%9B%BE%E8%AE%BA/"}]},{"title":"第十四届CB蓝桥省赛","slug":"第十四届CB蓝桥省赛","date":"2023-04-11T00:46:33.000Z","updated":"2023-04-11T01:46:43.335Z","comments":true,"path":"2023/04/11/第十四届CB蓝桥省赛/","link":"","permalink":"https://sealofyou.github.io/2023/04/11/%E7%AC%AC%E5%8D%81%E5%9B%9B%E5%B1%8ACB%E8%93%9D%E6%A1%A5%E7%9C%81%E8%B5%9B/","excerpt":"","text":"第十四届蓝桥杯大赛软件赛省赛 C/C++ 大学 B 组 试题A日期统计 题目 题目链接 image-20230411085046212 1235 6 8 6 9 1 6 1 2 4 9 1 9 8 2 3 6 4 7 7 5 9 5 0 3 8 7 5 8 1 5 8 6 1 8 3 0 3 7 9 27 0 5 8 8 5 7 0 9 9 1 9 4 4 6 8 6 3 3 8 5 1 6 3 4 6 7 0 7 8 2 7 6 8 9 5 6 5 6 1 4 0 10 0 9 4 8 0 9 1 2 8 5 0 2 5 3 3 答案:235 思路 考场思路: 暴力2023xxxx约是O(1008)?铁T,根本跑不完。 又因为2023不变,所以先找到2023(眼看,第58个是3,前面出现了202子序列),再对后面遍历所有子序列情况,存到map里。O(414) 最后遍历所有日期,map出现过就res++。 代码: 1234567891011121314151617181920212223242526272829303132333435363738#include<bits/stdc++.h>using namespace std;int a[100];map<int,int> mp;int res = 0;int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int main(){ freopen("A.txt","r", stdin); for(int i = 1; i <= 41; i ++) { cin >> a[i]; } for(int i1 = 1; i1 <= 41; i1 ++) { for(int i2 = i1 + 1; i2 <= 41; i2 ++) { for(int i3 = i2 + 1; i3 <= 41; i3 ++) { for(int i4 = i3 + 1; i4 <= 41; i4 ++) { int num = a[i1] * 1000 + a[i2] * 100 + a[i3] * 10 + a[i4]; mp[num] = 1; } } } } for(int i = 1; i <= 12; i ++) { for(int j = 1; j <= days[i]; j ++) { if(mp[100 * i + j] == 1)res ++; } } cout << res; return 0;} 可能正解: 对所有天数判断。O(365*100) 代码: 1234567891011121314151617181920212223242526272829303132333435363738394041#include<bits/stdc++.h>using namespace std;int a[1000];int res = 0;int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};bool check(string s){ int num = 1; for(int i = 1; i <= 100; i ++) { // 转成string才能比较 string d = to_string(a[i]); if(s[num] == d[0])num ++; if(num > 8)return 1; } return 0;}int main(){ // freopen("A2.txt","r", stdin); for(int i = 1; i <= 100; i ++) { cin >> a[i]; } for(int i = 1; i <= 12; i ++) { for(int j = 1; j <= days[i]; j ++) { // i,j用string存才不乱码 string s = "02023"; if(i < 10)s += "0"; s += to_string(i); if(j < 10)s += "0"; s += to_string(j); if(check(s))res ++; } } cout << res; return 0;} 试题 B: 01 串的熵 题目 题目链接 image-20230411094436776 思路 考场思路: 看不懂,心态崩了不想写。 填个114514得了。 可能正解:暴力","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"蓝桥杯","slug":"蓝桥杯","permalink":"https://sealofyou.github.io/tags/%E8%93%9D%E6%A1%A5%E6%9D%AF/"},{"name":"竞赛复盘","slug":"竞赛复盘","permalink":"https://sealofyou.github.io/tags/%E7%AB%9E%E8%B5%9B%E5%A4%8D%E7%9B%98/"}]},{"title":"4275. Dijkstra序列","slug":"4275-Dijkstra序列","date":"2023-04-04T12:48:16.000Z","updated":"2023-04-04T13:00:24.681Z","comments":true,"path":"2023/04/04/4275-Dijkstra序列/","link":"","permalink":"https://sealofyou.github.io/2023/04/04/4275-Dijkstra%E5%BA%8F%E5%88%97/","excerpt":"","text":"4275.Dijkstra序列 原题链接 思路 Dijkstra板子改改(内部判断一下能否实现即可) 代码 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768#include<bits/stdc++.h>using namespace std;const int N = 1010;int g[N][N];int dist[N];bool st[N];int fl[N];int n,m,k;bool dj(){ memset(dist, 0x3f, sizeof dist); //这里st忘了复原了,所以我当时出错。 memset(st, 0, sizeof st); dist[fl[1]] = 0; for(int t = 1; t <= n; t ++) { // 我的写法 int i = -1; for(int j = 1; j <= n; j ++) if(!st[j] && (i == -1 || dist[i] >= dist[j])) { // 需要判断是否是数列给的数,所以等于时需要加上 if(dist[i] == dist[j]) { if(i != fl[t])i = j; // i == fl[t]时i不变即可 continue; } i = j; } if(i != fl[t])return false; // y总写法 //int i = fl[i]; // for(int j = 1; j <= n; j ++) // if(!st[j] && dist[i] >= dist[j]) // { // return false; // } st[i] = true; for(int j = 1; j <= n; j ++) { dist[j] = min(dist[j], dist[i] + g[i][j]); } } return true;}int main(){ memset(g, 0x3f, sizeof g); cin >> n >> m; while(m --) { int a, b, c; cin >> a >> b >> c; g[a][b] = min(g[a][b], c); g[b][a] = min(g[b][a], c); } cin >> k; while(k --) { for(int i = 1; i <= n; i ++)cin >> fl[i]; if(dj())cout << "Yes" << endl; else cout << "No" << endl; } return 0;}","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"},{"name":"Dijkstra","slug":"Dijkstra","permalink":"https://sealofyou.github.io/tags/Dijkstra/"}]},{"title":"3777. 砖块(每日一题)","slug":"3777-砖块(每日一题)","date":"2023-03-30T11:48:33.000Z","updated":"2023-03-30T12:04:38.002Z","comments":true,"path":"2023/03/30/3777-砖块(每日一题)/","link":"","permalink":"https://sealofyou.github.io/2023/03/30/3777-%E7%A0%96%E5%9D%97%EF%BC%88%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%98%EF%BC%89/","excerpt":"","text":"AcWing 3777. 砖块(每日一题) 原题链接 思路 1.审题:判断出当B砖和W砖都为奇数个时不成立 每次翻转会使两个砖变为另一种颜色或两个砖交换颜色。所以颜色都为奇数个时将无法翻转成同一种颜色。 2.暴力 + 判暴力复杂度 思路:分别判断全为B或全为W时需要多少步。 方法: 从左到右==-1个==判断是否为需要颜色,不是就翻一下它和它后面的(-1的由来)。 判断最后一个和前面颜色是否相同,不同则选择另一个(下题解将此总数+1e7保证选到另一个) 时间复杂度:O(nt)(t组数,n操作数) 代码 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970#include<bits/stdc++.h>using namespace std;const int N = 210;int n,m;string s,cp;int num1[N],sum1 = 0;int num2[N],sum2 = 0;void change(int i){ if(s[i] == 'B')s[i] = 'W'; else s[i] = 'B';}int main(){ int t;cin >> t; while(t --) { m = 0,sum1 = sum2 = 0; cin >> n >> s; for(int i = 0; i < n; i ++)cp[i] = s[i]; // cout << cp << endl; for(int i = 0; i < n; i ++) { if(s[i] == "B")m ++; } if(m % 2 == 1 && (n - m) % 2 == 1) { cout << "-1" << endl; continue; } // 化成全B for(int i = 0; i < n - 1; i ++) { if(s[i] != 'B') { change(i),change(i + 1); num1[++ sum1] = i + 1; } } if(s[n-1] == 'W')sum1 +=1e7; // 化成全W for(int i = 0; i < n; i ++)s[i] = cp[i]; for(int i = 0; i < n - 1; i ++) { if(s[i] != 'W') { change(i),change(i + 1); num2[++ sum2] = i + 1; } } if(s[n-1] == 'B')sum2 +=1e7; if(sum1 < sum2) { cout << sum1 <<endl; if(sum1 != 0) { for(int i = 1; i <= sum1; i ++)cout << num1[i] << " "; cout << endl; } }else { cout << sum2 <<endl; if(sum2 != 0) { for(int i = 1; i <= sum2; i ++)cout << num2[i] << " "; cout << endl; } } }} 问题(我出的) memcpy不能对string用,要换成char s[N] image-20230330200432110 char,string的某一位s[i]与 字符 求 相等 时要用单引号而不是双引号! image-20230330200339142","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"},{"name":"递推","slug":"递推","permalink":"https://sealofyou.github.io/tags/%E9%80%92%E6%8E%A8/"}]},{"title":"导数的计算","slug":"导数的计算","date":"2023-03-19T02:41:40.000Z","updated":"2023-03-19T02:45:30.354Z","comments":true,"path":"2023/03/19/导数的计算/","link":"","permalink":"https://sealofyou.github.io/2023/03/19/%E5%AF%BC%E6%95%B0%E7%9A%84%E8%AE%A1%E7%AE%97/","excerpt":"","text":"导数的计算 导数表(部分)","categories":[{"name":"考研","slug":"考研","permalink":"https://sealofyou.github.io/categories/%E8%80%83%E7%A0%94/"}],"tags":[{"name":"数学","slug":"数学","permalink":"https://sealofyou.github.io/tags/%E6%95%B0%E5%AD%A6/"},{"name":"考研","slug":"考研","permalink":"https://sealofyou.github.io/tags/%E8%80%83%E7%A0%94/"}]},{"title":"极限","slug":"极限","date":"2023-03-17T02:49:13.000Z","updated":"2023-03-19T05:05:33.225Z","comments":true,"path":"2023/03/17/极限/","link":"","permalink":"https://sealofyou.github.io/2023/03/17/%E6%9E%81%E9%99%90/","excerpt":"","text":"求极限 方法: 先定型后定法,定法之前先四化 定型 未定式:化简 -> 定法 已定式:带入求极限 化简 非0因子可淡化 加减法中存在可拆化 \"\\(\\sqrt{x}\\)\"有理化 幂指函数幂指转换 定法 等价无穷小代换(x->0时) 泰勒公式 洛必达法则 极限四则运算 7种未定式(题型) 0比0型 \\[\\frac{0}{0} \\] 等价无穷小代换(x->0时) 泰勒公式 洛必达法则 极限四则运算 \\(\\infty\\)比\\(\\infty\\) 型 \\[\\frac{\\infty}{\\infty} \\] 抓大头 上下同除最大项 洛必达法则 0 * \\(\\infty\\)型 将其化为0比0 \\[\\frac{ 0 }{ \\frac{ 1 }{ \\infty }} = \\frac{0}{0} \\] 将其化为\\(\\infty\\)比\\(\\infty\\) \\[\\frac{\\infty}{\\frac{1}{\\infty}} = \\frac{\\infty}{\\infty} \\] \\(\\infty - \\infty\\) 型 通分 使 \\[ x=\\frac{1}{t} \\] \\(1^{\\infty}\\)型 重要公式: \\(\\lim f(x)^{g(x)} = e^{\\lim g(x)\\ln f(x)-1}\\) \\(0^{\\infty}\\)和\\(0^{0}\\) 型 幂指转换","categories":[{"name":"考研","slug":"考研","permalink":"https://sealofyou.github.io/categories/%E8%80%83%E7%A0%94/"}],"tags":[{"name":"数学","slug":"数学","permalink":"https://sealofyou.github.io/tags/%E6%95%B0%E5%AD%A6/"},{"name":"考研","slug":"考研","permalink":"https://sealofyou.github.io/tags/%E8%80%83%E7%A0%94/"}]},{"title":"1230. K倍区间","slug":"1230-K倍区间","date":"2023-02-18T04:47:31.000Z","updated":"2023-02-18T04:57:46.205Z","comments":true,"path":"2023/02/18/1230-K倍区间/","link":"","permalink":"https://sealofyou.github.io/2023/02/18/1230-K%E5%80%8D%E5%8C%BA%E9%97%B4/","excerpt":"","text":"1230. K倍区间 原题链接 思路 前缀和应用 正常想法O(n^2) 求前缀和后根据端点遍历另一个端点。 想到求余数(性质)可优化到O(n) 前缀和是a1~ai的和,那么a? ~ ai的和的余数为0只要a1~a?的余数等于a? ~ai的余数即可。 所以用一个新数组存前缀和余数,然后直接根据判断满足的个数即可。 相当于优化掉了根据端点遍历另一个端点的时间。 注意 LL问题(a[i]要用LL,我这里%k了可以不用) 代码 1234567891011121314151617181920212223#include<bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int n, k;int a[N], c[N];int main(){ cin >> n >> k; for(int i = 1; i <= n; i ++) { cin >> a[i]; a[i] = (a[i] + a[i - 1]) % k; } long long res = 0; c[0] ++; for(int i = 1; i <= n; i ++)//右端点 { res += c[a[i] % k]; c[a[i] % k] ++; } cout<< res;}","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"},{"name":"前缀和","slug":"前缀和","permalink":"https://sealofyou.github.io/tags/%E5%89%8D%E7%BC%80%E5%92%8C/"}]},{"title":"3956. 截断数组","slug":"3956-截断数组","date":"2023-02-15T00:30:41.000Z","updated":"2023-02-15T00:42:55.562Z","comments":true,"path":"2023/02/15/3956-截断数组/","link":"","permalink":"https://sealofyou.github.io/2023/02/15/3956-%E6%88%AA%E6%96%AD%E6%95%B0%E7%BB%84/","excerpt":"","text":"3956.截断数组 原题链接 思路 截两段,三数组各元素和相等。 求截断方法数。 判断特殊情况 输入时求总数sum,sum不是3的倍数直接输出0结束。 sum为0时,公式求解。 记得long long。 前缀和求a[1] ~ a[i]是多少,求等于sum/3和sum/3*2的个数 从头到尾求方案数 事件复杂度:O(n) 代码 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263#include<bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int a[N];int main(){ int n; cin >> n; int sum = 0; for(int i = 1; i <= n; i ++) { cin >> a[i]; sum +=a[i]; a[i] += a[i - 1]; } if(n < 3) { cout << 0; return 0; } if(sum % 3 != 0) { cout << 0; return 0; } if(sum == 0) { /* 3 0 1 (n-2) 4 0 3 (n-2) +(n-3) ... n 0 res (1 + (n-2)) * (n-2) */ int num = 0; for(int i = 1; i <= n; i ++) { if(a[i] == sum)num ++; } cout << (long long)(1 + (num - 2)) * (num - 2) / 2; return 0; } sum /= 3; int num1 = 0, num2 = 0; for(int i = 1; i <= n; i ++) { if(a[i] == sum)num1 ++; if(a[i] == sum * 2)num2 ++; } // cout << num1 << " " << num2 << endl; long long res = 0; for(int i = 1; i <= n; i ++) { if(a[i] == sum) { res += num2; } if(a[i] == sum * 2){ num2 --; } } cout << res; return 0;}","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"},{"name":"前缀和","slug":"前缀和","permalink":"https://sealofyou.github.io/tags/%E5%89%8D%E7%BC%80%E5%92%8C/"}]},{"title":"hexo上线服务器","slug":"hexo上线服务器","date":"2023-02-14T09:52:40.000Z","updated":"2023-02-14T09:56:18.587Z","comments":true,"path":"2023/02/14/hexo上线服务器/","link":"","permalink":"https://sealofyou.github.io/2023/02/14/hexo%E4%B8%8A%E7%BA%BF%E6%9C%8D%E5%8A%A1%E5%99%A8/","excerpt":"","text":"hexo部署服务器 实现原理 nginx应用 步骤 上线github或gitee 省略 新建镜像 有原来镜像(新建)直接 1docker run -p 80:80 -p 443:443 -p 20025:22 -itd --name blog seal:latest 安装nginx sudo apt install nginx 修改/etc/nginx/sites-avaliable的default sudo打开default(谨防改完发现改不了诈骗) 12cd ../../etc/nginx/sites-avaliablesudo vim default 修改部分 12root /var/www/html 改为 root hexo博客文件夹绝对目录。server_name _;添加IP或服务器域名。 image-20230214174457128 重启nginx nginx -s reload 缺点 每次都要 1git pull","categories":[{"name":"博客","slug":"博客","permalink":"https://sealofyou.github.io/categories/%E5%8D%9A%E5%AE%A2/"}],"tags":[{"name":"部署服务器","slug":"部署服务器","permalink":"https://sealofyou.github.io/tags/%E9%83%A8%E7%BD%B2%E6%9C%8D%E5%8A%A1%E5%99%A8/"}]},{"title":"95.费解的开关","slug":"95.费解的开关","date":"2022-03-02T11:33:29.000Z","updated":"2023-02-08T14:32:14.201Z","comments":true,"path":"2022/03/02/95.费解的开关/","link":"","permalink":"https://sealofyou.github.io/2022/03/02/95.%E8%B4%B9%E8%A7%A3%E7%9A%84%E5%BC%80%E5%85%B3/","excerpt":"","text":"95.费解的开关 AcWing 95. 费解的开关 你玩过“拉灯”游戏吗? 25盏灯排成一个 5×5的方形。 每一个灯都有一个开关,游戏者可以改变它的状态。 每一步,游戏者可以改变某一个灯的状态。 游戏者改变一个灯的状态会产生连锁反应:和这个灯上下左右相邻的灯也要相应地改变其状态。 我们用数字 1表示一盏开着的灯,用数字 0表示关着的灯。 下面这种状态 123451011101101101111000011011 在改变了最左上角的灯的状态后将变成: 123450111111101101111000011011 再改变它正中间的灯后状态将变成: 123450111111001110011010011011 给定一些游戏的初始状态,编写程序判断游戏者是否可能在 6步以内使所有的灯都变亮。 输入格式 第一行输入正整数 n,代表数据中共有 n个待解决的游戏初始状态。 以下若干行数据分为 n组,每组数据有 5 行,每行 5个字符。 每组数据描述了一个游戏的初始状态。 各组数据间用一个空行分隔。 输出格式 一共输出 n行数据,每行有一个小于等于 6的整数,它表示对于输入数据中对应的游戏状态最少需要几步才能使所有灯变亮。 对于某一个游戏初始状态,若 6步以内无法使所有灯变亮,则输出 −1。 数据范围 0<n≤500 输入样例: 1234567891011121314151617183001110101110001110101110011101111011111011111111110111111111111111111111111 输出样例: 12332-1 题解: 首先我们要想到更改第i行的某一个灯(不改变同一行其它灯的状态)是改变这个灯上(下)的灯。 由此我们可以定下从上到下的方向来一行一行枚举灯的亮灭情况(灭就点亮)。(递推由来) 由于我们从上向下枚举,而这种枚举只改变第2-5行的灯,无法判断第一行是否有所更改会导致更少的步数,所以需要枚举第一行所有情况(32钟)。 ps:因为3中的原因,为了简化枚举所有情况的代码[doge],使用了位运算的操作。 代码: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#include<bits/stdc++.h>using namespace std;const int N=10;char a[N][N],b[N][N];int dx[5]={0,-1,0,1,0},dy[5]={0,0,-1,0,1};void turn(int x,int y){ for(int i=0;i<5;i++) { int tx=x+dx[i],ty=y+dy[i]; if(tx<0 && tx>=5 && ty<0 && ty>=5)continue; a[tx][ty]^=1;//0->1,1->0的高级操作。 }}int main(){ int t;cin>>t; while(t--) { for(int i=0;i<5;i++)cin>>a[i]; memcpy(b,a,sizeof a); int res=10; for(int op=0;op<32;op++) { int sum=0; for(int i=0;i<5;i++)if(op>>i&1)turn(0,i),sum++;//如果这个数第i位是1,turn(0,i) for(int i=0;i<4;i++) { for(int j=0;j<5;j++) { if(a[i][j]=='0')turn(i+1,j),sum++; if(sum>res)break; } if(sum>res)break; } int fl=1; for(int i=0;i<5;i++) { if(a[4][i]=='0')fl=0; } if(fl==1)res=min(res,sum); memcpy(a,b,sizeof b); } if(res<=6)cout<<res<<endl; else cout<<-1<<endl; }}","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"}]},{"title":"#767div2","slug":"767div2","date":"2022-01-27T08:37:34.000Z","updated":"2022-01-27T08:39:08.938Z","comments":true,"path":"2022/01/27/767div2/","link":"","permalink":"https://sealofyou.github.io/2022/01/27/767div2/","excerpt":"","text":"#767(div2) 感受 掉大分,思路没问题代码各种手误,卡手了。 还有如果有思路不要一会换一道,一会换一道,认真思考而不是换题。 A. Download More RAM 原题链接 题意: 加内存,有n个加内存的软件,每个需要ai,打开后返回ai并增加bi。求最大的内存。 分析: 按a从小到大排序,从头开始遍历,到第一个不满足条件的跳出,此时内存为最大值。 代码: 1234567891011121314151617181920212223242526#include<bits/stdc++.h>#define x first#define y secondusing namespace std;const int N=110;typedef pair<int, int> PII;PII a[N];int n,k;int main(){ int t;cin>>t; while(t--) { cin>>n>>k; for(int i=1;i<=n;i++)cin>>a[i].x; for(int i=1;i<=n;i++)cin>>a[i].y; sort(a+1,a+n+1); for(int i=1;i<=n;i++) { if(a[i].x<=k)k+=a[i].y; else break; } cout<<k<<endl; }} B. GCD Arrays 原题链接 题意: 给l,r,k。求区间[l,r]内k个操作内其中任意两个数gcd不为1。 分析: 因为数据极大,所以不可能求gcd,肯定是找规律。 特判+求奇数个数。 如果k大于等于奇数个数,输出YES,不然输出NO。 特判:l==r的时候,除了1是NO,以外均是YES 代码: 1234567891011121314151617181920212223242526#include<bits/stdc++.h>using namespace std;int l,r,k;int main(){ int t;cin>>t; while(t--) { cin>>l>>r>>k; if(r==1) { cout<<"NO"<<endl; continue; } if(l==r && l!=1) { cout<<"YES"<<endl; continue; } int num=(r-l)/2; if((r-l)%2==1)num++; if(r%2==1 && l%2==1)num++; if(num<=k)cout<<"YES"<<endl; else cout<<"NO"<<endl; }} C. Meximum Array 原题链接 题意: 新定义MEX概念:数组内第一个没有的非负整数 e.g.MEX({1,2,31,2,3}) =0=0 and MEX({0,1,2,4,50,1,2,4,5}) =3=3. 给定一个数组a,取出前k个数求MEX放到最后,然后从剩下的继续,直到a数组为空。求b数组最大(仅按第几位比较,不比长度)的情况下的长度及每次取出k个数的MEX值。 分析: 贪心。 因为n<2*105,所以可以维护一个桶寻找MEX最大值num,然后根据每次找到的MEX最大值遍历a数组,直到满足。记录sum,num的值并重复,直到a数组为空。 代码: 123456789101112131415161718192021222324252627282930313233343536373839404142434445#include<bits/stdc++.h>using namespace std;const int N=200010;int a[N];int s[N],st[N];int b[N];int main(){ int t;cin>>t; while(t--) { int n;cin>>n; for(int i=1;i<=n;i++) { int num; cin>>num; s[num]++; a[i]=num; } int sum=0; for(int k=1;k<=n;k++) { int num=0,op=0,fl=0; while (s[num])num++; for(int i=k;i<=n;i++) { s[a[i]]--; if(!st[a[i]] && a[i]<=num)op++,st[a[i]]=1; //当时判断写错了,写成st[i]了艹 if(op==num) { b[sum++]=num; for(int j=0;j<=num;j++)st[j]=0; k=i;fl=1; break; } } } cout<<sum<<endl; for(int i=0;i<sum;i++)cout<<b[i]<<' '; cout<<endl; }} D. Peculiar Movie Preferences 原题链接 题意: n个长度不超过3的字符串,使其组合成回文串。 跳过场景,而不是随意选。 分析: 分情况讨论 字符长度是1:是回文。 字符长度是2:存进map,reverse然后看是否有回文。 字符长度是3:判自己是否是回文,不是的话存进map,reverse然后看是否有回文。没有的话 前两位放到map中并于之前长度为二的分开(map存的值不一样)。 后两位reverse后从之前字符长度为2中找是否有回文。 以上所有只要有一个回文条件满足,那么输出YES,不然输出NO 代码: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162#include<bits/stdc++.h>using namespace std;const int N=100010;string s;int main(){ int t;cin>>t; while(t--) { int n;cin>>n; map<string,int> q,p; int fl=0; for(int i=1;i<=n;i++) { cin>>s; if(fl==1)continue; if(s.size()==1)//串长为1,回文 { fl=1;continue; } if(s.size()==2)//串长为2,找之前是否有对应回文出现,并放入新串 { q[s]=1; swap(s[0],s[1]); if(q[s]!=0)fl=1;//2-2 }else { //串长为3,前中两位放map里,中后两位找前面是否有对应回文 if(s[0]==s[2])//回文 { fl=1; continue; } //3-3 必须先判3-3,不然用3-2的判法会有问题 q[s]=1; swap(s[0],s[2]); if(q[s]==1)fl=1; else { swap(s[0],s[2]); string l,r; //l 3-2 l+=s[0];l+=s[1]; q[l]=2; //r 2-3 r+=s[1];r+=s[2]; swap(r[0],r[1]); if(q[r]==1)fl=1; } } } if(fl)cout<<"YES"<<endl; else cout<<"NO"<<endl; }}/*特殊数据2cabaac*/","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"题解","slug":"题解","permalink":"https://sealofyou.github.io/tags/%E9%A2%98%E8%A7%A3/"},{"name":"codeforce","slug":"codeforce","permalink":"https://sealofyou.github.io/tags/codeforce/"}]},{"title":"传智杯","slug":"传智杯","date":"2021-12-19T12:07:36.000Z","updated":"2023-03-19T02:50:07.577Z","comments":true,"path":"2021/12/19/传智杯/","link":"","permalink":"https://sealofyou.github.io/2021/12/19/%E4%BC%A0%E6%99%BA%E6%9D%AF/","excerpt":"","text":"传智杯 感受: 个人参加的b组,3道签到题+1道暴力/算法题+1道算法题。 前三题卡到我的是看错题了,舍去小数部分看成整数输出,所以拿了double整数输出(四舍五入),导致wa了。 第四题找二进制规律优化,因为不会就只写了一个暴力的解法过了3/4左右(?可能吧,一个代码TLE1-16都有过)数据。 题解: A.组原成绩 A 等级:语法题 解析: 依据题意直接输出整数即可。 代码: 1234567891011#include<bits/stdc++.h>using namespace std;int main(){ double t,h,e; cin>>t>>h>>e; double s=0.2*t+h*0.3+e*0.5; int s1=s; printf("%d",s1); return 0;} B.报告赋分 B 等级:语法题 解析: 给定一个t,接下来t行每行有一个卷面基础分a和页数p。 根据页数p减卷面分(题意)就行了。 代码: 123456789101112131415#include<bits/stdc++.h>using namespace std;int main(){ int t;cin>>t; while(t--) { int a,b; cin>>a>>b; if(b<16)a=max(a-10,0); else if(b>20)a=max(a-(b-20),0); cout<<a<<endl; } return 0;} C.竞争得分 C 等级:语法题 解析: n表示人数,接下来n个数a1-an。 用数组存a1-an,用ma,mi存最大值和最小值。然后每个数进行一遍得分的运算+输出就行了。 代码: 12345678910111213141516171819202122#include<bits/stdc++.h>using namespace std;const int N=100010;double a[N];int main(){ int n;cin>>n; double ma=0,mi=10000; for(int i=1;i<=n;i++) { cin>>a[i]; ma=max(ma,a[i]); mi=min(mi,a[i]); } for(int i=1;i<=n;i++) { a[i]=100*(a[i]-mi)/(ma-mi); int sb=a[i];//直接整数输出double的话会因为小数部分四舍五入而出错 printf("%d ",sb); } return 0;} D.小卡与质数2 D 等级:算法题 解析:二进制规律优化 我的解法是一种简单的暴力写法。首先筛质数板子把1e6的所有质数筛出来,然后让小于x的非负整数与其按位异或,最后利用二分查找异或后的数是否是质数,是sum++。时间复杂度O(nmlogcnt),铁过不了但是交的代码会在#1-#16之间TLE,且每次基本不相同。 正解后补。 代码: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798//我知道我过不了但是TLE数据一直在变的代码#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int N = 1e6+10;int primes[N],cnt;bool st[N];void init(int n){ for(int i=2;i<=n;i++) { if(!st[i])primes[cnt++]=i; for(int j=0;primes[j]*i<=n;j++) { st[primes[j]*i]=1; if(i%primes[j]==0)break; } }}int main(){ int n; cin>>n; init(1000010); while(n--) { int x;cin>>x; int sum=0; for(int i=0;i<x;i++) { int t1=x^i; int t=lower_bound(primes,primes+cnt,t1)-primes; if(primes[t]==t1)sum++; } cout<<sum<<endl; } }//周围巨佬的AC代码#include<iostream>#include<algorithm>#include<cstdio>using namespace std;const int N=2e6+10;int pr[N],idx,len=0,res=0;bool st[N];void init(int n){ for(int i=2;i<=n;i++) { if(!st[i]) pr[idx++]=i; for(int j=0;pr[j]<=n/i;j++) { st[pr[j]*i]=1; if(i%pr[j]==0) break; } }}int find(int x){ int num=1,len=0; while(x) { num=num*2; if(x&1) { int t=1; for(int i=1;i<=len;i++) t=t*2; //cout<<num<<' '<<t<<' '; int r=upper_bound(pr,pr+idx,num-1)-pr; int l=lower_bound(pr,pr+idx,t)-pr; //cout<<l<<' '<<r<<endl; res+=r-l; } len++; x>>=1; } return num;}int main(){ //freopen("1.txt","r",stdin); init(N-10); int T; cin>>T; //cout<<idx<<' '; while(T--) { int x; cin>>x; len=0;res=0; int l=1,r; r=find(x); cout<<res<<endl; }} E.萝卜数据库 E 等级:语法题-算法题 解析: 插入时:用二维数组第一维存字段x,第二维存值y,数组值存出现次数。 查找时:ma[x] [ymi-yma]之和。 代码: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879//二维数组#include<bits/stdc++.h>using namespace std;const int N=1010;int a[N][N],sum[N];int main(){ int n,k; cin>>n>>k; int b,p,x,y; for(int i=1;i<=n;i++) { cin>>b; if(b==1) { cin>>p; for(int i=1;i<=p;i++) { cin>>x>>y; a[x][y]++; } } else { int yma,ymi; cin>>x>>ymi>>yma; int sum=0; for(int i=ymi;i<=yma;i++) { sum+=a[x][i]; //cout<<endl<<x<<i<<endl; } cout<<sum<<endl; } }}//哈希写法#include<bits/stdc++.h>using namespace std;const int N=1010;int a[N][N],sum[N];unordered_map<int,int> ma[N];int main(){ int n,k; cin>>n>>k; int b,p,x,y; for(int i=1;i<=n;i++) { cin>>b; if(b==1) { cin>>p; for(int i=1;i<=p;i++) { cin>>x>>y; ma[x][y]++; //cout<<' '<<x<<' '<<y<<ma[x][y]<<endl; } } else { int yma,ymi; cin>>x>>ymi>>yma; int sum=0; for(int i=ymi;i<=yma;i++) { sum+=ma[x][i]; //cout<<endl<<x<<i<<endl; } cout<<sum<<endl; } }}","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"题解","slug":"题解","permalink":"https://sealofyou.github.io/tags/%E9%A2%98%E8%A7%A3/"},{"name":"传智杯","slug":"传智杯","permalink":"https://sealofyou.github.io/tags/%E4%BC%A0%E6%99%BA%E6%9D%AF/"}]},{"title":"校赛题解","slug":"校赛题解","date":"2021-12-14T11:33:17.000Z","updated":"2023-03-19T02:51:42.971Z","comments":true,"path":"2021/12/14/校赛题解/","link":"","permalink":"https://sealofyou.github.io/2021/12/14/%E6%A0%A1%E8%B5%9B%E9%A2%98%E8%A7%A3/","excerpt":"","text":"2021校赛: 感受: 校赛算是选拔蓝桥杯省赛,但是这次题目给了1道签到题+两道语法题+2道算法题(可以保证基本没人写出来的那种)。所以导致只要语法有基础+手速够快就能得奖并且获得蓝桥杯参赛资格。 然而,因为最后一题因为数据问题(过于氵),导致只要稍微有点思路就能AC,但其实正解没有人写出来,所以这次的校赛其实真的氵。 题解: A 等级:语法题 解析: 从最后一天剩一个开始向前推,每向前一天+1然后*2,总共n-1天。 一个for循环就行。 代码: 12345678910111213141516171819202122232425262728//c#include<stdio.h>int main(){ int n; scanf("%d",&n); int sum=1; for(int i=1;i<n;i++) { sum=(sum+1)*2; } printf("%d"sum); return 0;}//c++#include<iostream>#include<algorithm>using namespace std;int main(){ int n;cin>>n; int sum=1; for(int i=1;i<n;i++) { sum=(sum+1)*2; } cout<<sum;} B 等级:语法题 解析: 将头左斜45°,它就变成了一个金字塔形状的数列,然后这样斜着进行更新(指填数)。 最后直接两重for控制输出即可。 代码: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253//c#include<stdio.h>int a[110][110];int main(){ int n; scanf("%d",&n); int num=1; for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { a[i-j+1][j]=num++; } } for(int i=1;i<=n+1;i++) { for(int j=1;j<=n-i+1;j++) { printf("%d "a[i][j]); } printf("\\n"); } }//c++#include<iostream>#include<algorithm>using namespace std;int a[110][110];int main(){ int n;cin>>n; int num=1; for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { a[i-j+1][j]=num++; } } //cout<<num<<endl; for(int i=1;i<=n+1;i++) { for(int j=1;j<=n-i+1;j++) { cout<<a[i][j]<<' '; } cout<<endl; } } C 等级:算法题(图的dfs) 解析: 首先要会图的存储,然后每个点dfs,并每次成立的时候情况++就行了。 (新生不建议写[doge]) 代码: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071//c++#include<bits/stdc++.h>using namespace std;const int N=100010;int h[N],e[N*2],ne[N*2],idx;int n,m,d[N],num=0;int st[N];int sum=0;void add(int a,int b){ e[idx]=b;ne[idx]=h[a];h[a]=idx++;}void dfs2(int u){ num++;st[u]=1; if(num==4) { sum++; return; } for(int i=h[u];i!=-1;i=ne[i]) { int j=e[i]; if(num==3 && st[j]==2) { sum++; continue; } else if(!st[j]) { dfs2(j); st[j]=0; num--; } } st[u]=0;}void dfs(int u){ num=1;st[u]=2; for(int i=h[u];i!=-1;i=ne[i]) { int j=e[i]; dfs2(j); num--; } st[u]=0;}int main(){ memset(h,-1,sizeof h); cin>>n>>m; for(int i=1;i<=m;i++) { int a,b; cin>>a>>b; add(a,b);add(b,a); d[a]++,d[b]++; }// if(n<=3 || m<=2)//比赛时写的特判情况之一// {// cout<<0;// return 0;// } for(int i=1;i<=n;i++) { dfs(i); } cout<<sum;} D 等级:语法题 解析: 大水题,我上课讲的都比这难。 时分秒表示出来然后输出就行,我上课讲的个位前补零的情况也没有。 时:a=t/3600 分:b=t%3600/60 秒:c=t%60 代码: 123456789101112131415161718192021222324//c#include<stdio.h>int main(){ int t; scanf("%d",&t); int a=t/3600,b=t%3600/60,c=t%60; printf("%d:%d:%d",a,b,c); }//c++#include<iostream>#include<algorithm>#include<cstdio>using namespace std;int main(){ int t;cin>>t; int a=t/3600,b=t%3600/60,c=t%60; printf("%d:%d:%d",a,b,c); } E 等级:语法题(暴力)~算法题(线性DP) 解析: 因为数据特别氵,所以只要思路还好的的暴力都可以过,但是暴力过了其实不代表个人实力。 然而正解是一个思路比较清奇(分组)的线性dp。 暴力可以问你们杨琳涵学姐、唐鑫学长、赵普学长(他说直接给你们讲线性dp的解法[doge])和我。 线性dp版可以找你们赵普学长。(我懒得讲) 新生不建议写(暴力建议练其他题,dp算法还没学) 代码: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182//暴力#include<iostream>#include<algorithm>#include<bits/stdc++.h>using namespace std;const int N=200010;int b[N],a[N],idx;bool st[N];int n,k;int main(){ cin>>n>>k; int t; for(int i=1;i<=n;i++) { cin>>t; if(!b[t])a[idx++]=t; b[t]++; } if(k==0) { cout<<idx; return 0; } sort(a,a+idx-1); int sum=0; for(int i=1;i<=k;i++) { sum+=b[i]; st[i]=1; for(int j=i+k;j<=100010;j+=k) { if(st[j-k]==1 && b[j-k]<b[j]) { sum+=b[j]-b[j-k]; st[j]=1;st[j-k]=0; }else if(st[j-k]==0) { sum+=b[j]; st[j]=1; } } } cout<<sum;}//dp#include<bits/stdc++.h>using namespace std;const int N=200010;int b[N],a[N],idx;int f[N],st[N];int n,k;int main(){ cin>>n>>k; int t; for(int i=1;i<=n;i++) { cin>>t; if(!b[t])a[idx++]=t; b[t]++; } if(k==0) { cout<<idx; return 0; } sort(a,a+idx-1); int sum=0,j,i; for(i=1;i<=k;i++) { int cnt=1; for(int j=i;j<=100000;j+=k,cnt++) { f[cnt]=f[cnt-1]; if(j>=2)f[cnt]=max(f[cnt-2]+b[j],f[cnt]); } sum+=f[cnt-1]; } cout<<sum;}","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"题解","slug":"题解","permalink":"https://sealofyou.github.io/tags/%E9%A2%98%E8%A7%A3/"}]},{"title":"ACgame","slug":"ACgame","date":"2021-12-13T03:32:54.000Z","updated":"2021-12-18T08:19:55.228Z","comments":true,"path":"2021/12/13/ACgame/","link":"","permalink":"https://sealofyou.github.io/2021/12/13/ACgame/","excerpt":"","text":"一个简单的小游戏 网址 https://app279.acapp.acwing.com.cn/","categories":[],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"},{"name":"game","slug":"game","permalink":"https://sealofyou.github.io/tags/game/"}]},{"title":"差分","slug":"差分","date":"2021-09-12T05:08:26.000Z","updated":"2021-12-13T15:02:57.860Z","comments":true,"path":"2021/09/12/差分/","link":"","permalink":"https://sealofyou.github.io/2021/09/12/%E5%B7%AE%E5%88%86/","excerpt":"","text":"差分 差分相当于前缀和的逆运算。 目的:数组中一段数+x时间复杂度降低 具体做法:假设一个数组的前缀和为原数组 一维差分: 预处理: 1234567int a[N],b[N];/*(1)*/for(int i=1;i<=n;i++)b[i]=a[i]-a[i-1];/*(2)*/for(int i=1;i<=n;i++){ b[i]+=a[i]; b[i+1]-=a[i];} 添加数: 1234567int l,r,c;while(m--){ cin>>l>>r>>c; b[l]+=c; b[r+1]-=c;} 二维差分: 差分函数: 1234567void insert(int x1,int y1,int x2,int y2,int c){ a[x1][y1]+=c; a[x2+1][y1]-=c; a[x1][y2+1]-=c; a[x2+1][y2+1]+=c;} 预处理: 12for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)insert(i,j,i,j,c); 添加数: 1insert(x1,y1,x2,y2,c);","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"}]},{"title":"前缀和","slug":"前缀和","date":"2021-09-12T04:56:09.000Z","updated":"2021-12-13T15:03:09.217Z","comments":true,"path":"2021/09/12/前缀和/","link":"","permalink":"https://sealofyou.github.io/2021/09/12/%E5%89%8D%E7%BC%80%E5%92%8C/","excerpt":"","text":"前缀和 目的:求原数组中某段数的和(O(1)) 具体做法:做一个预处理,定义一个新数组储存原数组前i个数的和 一维前缀和: 预处理: 12int sum[N],a[N];for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i]; 查找:(求l~r之间的数) 1num=sum[r]-sum[l-1]; 二维前缀和:(当成方格形) 预处理: 1234int sum[N][M],a[N][M];for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) sum[i][j]=sum[i-1][j-1]-sum[i-1][j]-sum[i][j-1]+a[i][j]; 查找:(求(l1,r1)~(l2,r2)之间的数) 1num=sum[l2][r2]-sum[l2][r1-1]-sum[l1-1][r2]+sum[l1][r1]; 高维前缀和:(类比)","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"}]},{"title":"STL","slug":"STL","date":"2021-09-11T09:30:06.000Z","updated":"2021-12-13T15:02:40.536Z","comments":true,"path":"2021/09/11/STL/","link":"","permalink":"https://sealofyou.github.io/2021/09/11/STL/","excerpt":"","text":"STL简记","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"}]},{"title":"hash","slug":"hash","date":"2021-09-11T07:47:14.000Z","updated":"2023-03-19T02:53:28.933Z","comments":true,"path":"2021/09/11/hash/","link":"","permalink":"https://sealofyou.github.io/2021/09/11/hash/","excerpt":"","text":"哈希表 目的:将大范围的多个数映射到一个0-N的集合中 常见哈希表: 1.普通哈希表 处理冲突方式: 1.开放寻址法 image-20210911164017945 123456789101112131415161718const int N=2e5+3,num=0x3f3f3f3f;int h[N];int find(int x){ int k=(x%N+N)%N; while(h[k]!=num&&h[k]!=x) { k++; if(k==N)k=0; }}//添加int k=find(x);h[k]=x;//查找int k=find(x);if(h[k]!=num)//存在 else //不存在 2.拉链法:一个数组存储所有哈希值 image-20210911155856034 常用操作:1.添加2.查找 3.删除(额外数组进行标记,不常用) 代码 123456789101112131415161718const int N=1e5+3;//减少冲突经常取模100003(大于最大集合范围的最小的质数)int h[N],e[N],ne[N],idx;void insert(int x)//添加{ int k=(x%N+N)%N; e[idx]=x; ne[idx]=h[k]; h[k]=idx++;}bool find(int x)//查找{ int k=(x%N+N)%N; for(int i=h[k];i!=-1;i=ne[i]) if(e[i]==x)return true; return false;} 2.字符串哈希 字符串前缀哈希法: 预处理所有前缀的哈希 1 1.如何定义前缀的哈希值:将其转化为p进制数 注:*1.不能将任何数映射为0 *2.不存在冲突时,p=131或13331、Q取2^64时,不存在冲突 image-2 好处:可以依照公式求出前缀的哈希值求出一段的哈希值 公式: \\[ h[R]-h[L-1]*p^(R-L+1) \\] 1234567891011121314151617181920212223242526272829#include<bits/stdc++.h>using namespace std;typedef unsigned long long ull;const int N=1e5+10,P=131;int n,m;char str[N];ull h[N],p[N];ull get(int l,int r){ return h[r]-h[l-1]*p[r-l+1];}int main(){ scanf("%d%d%s",&n,&m,str+1); p[0]=1; for(int i=1;i<=n;i++) { p[i]=p[i-1]*P; h[i]=h[i-1]*P+str[i]; } while(m--) { int l1,l2,r1,r2; cin>>l1>>r1>>l2>>r2; if(get(l1,r1)==get(l2,r2))cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0;}","categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"}],"tags":[{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"}]},{"title":"Introduction","slug":"Introduction","date":"2021-09-10T09:54:09.000Z","updated":"2021-12-13T15:02:24.214Z","comments":true,"path":"2021/09/10/Introduction/","link":"","permalink":"https://sealofyou.github.io/2021/09/10/Introduction/","excerpt":"","text":" 学着搭了个简单的博客,用来简单记录自己的算法学习和游戏相关。","categories":[],"tags":[]}],"categories":[{"name":"算法","slug":"算法","permalink":"https://sealofyou.github.io/categories/%E7%AE%97%E6%B3%95/"},{"name":"slidev","slug":"slidev","permalink":"https://sealofyou.github.io/categories/slidev/"},{"name":"hexo","slug":"hexo","permalink":"https://sealofyou.github.io/categories/hexo/"},{"name":"考研","slug":"考研","permalink":"https://sealofyou.github.io/categories/%E8%80%83%E7%A0%94/"},{"name":"博客","slug":"博客","permalink":"https://sealofyou.github.io/categories/%E5%8D%9A%E5%AE%A2/"}],"tags":[{"name":"图论","slug":"图论","permalink":"https://sealofyou.github.io/tags/%E5%9B%BE%E8%AE%BA/"},{"name":"最短路","slug":"最短路","permalink":"https://sealofyou.github.io/tags/%E6%9C%80%E7%9F%AD%E8%B7%AF/"},{"name":"slidev","slug":"slidev","permalink":"https://sealofyou.github.io/tags/slidev/"},{"name":"hexo","slug":"hexo","permalink":"https://sealofyou.github.io/tags/hexo/"},{"name":"蓝桥杯","slug":"蓝桥杯","permalink":"https://sealofyou.github.io/tags/%E8%93%9D%E6%A1%A5%E6%9D%AF/"},{"name":"竞赛复盘","slug":"竞赛复盘","permalink":"https://sealofyou.github.io/tags/%E7%AB%9E%E8%B5%9B%E5%A4%8D%E7%9B%98/"},{"name":"AcWing","slug":"AcWing","permalink":"https://sealofyou.github.io/tags/AcWing/"},{"name":"Dijkstra","slug":"Dijkstra","permalink":"https://sealofyou.github.io/tags/Dijkstra/"},{"name":"递推","slug":"递推","permalink":"https://sealofyou.github.io/tags/%E9%80%92%E6%8E%A8/"},{"name":"数学","slug":"数学","permalink":"https://sealofyou.github.io/tags/%E6%95%B0%E5%AD%A6/"},{"name":"考研","slug":"考研","permalink":"https://sealofyou.github.io/tags/%E8%80%83%E7%A0%94/"},{"name":"前缀和","slug":"前缀和","permalink":"https://sealofyou.github.io/tags/%E5%89%8D%E7%BC%80%E5%92%8C/"},{"name":"部署服务器","slug":"部署服务器","permalink":"https://sealofyou.github.io/tags/%E9%83%A8%E7%BD%B2%E6%9C%8D%E5%8A%A1%E5%99%A8/"},{"name":"题解","slug":"题解","permalink":"https://sealofyou.github.io/tags/%E9%A2%98%E8%A7%A3/"},{"name":"codeforce","slug":"codeforce","permalink":"https://sealofyou.github.io/tags/codeforce/"},{"name":"传智杯","slug":"传智杯","permalink":"https://sealofyou.github.io/tags/%E4%BC%A0%E6%99%BA%E6%9D%AF/"},{"name":"game","slug":"game","permalink":"https://sealofyou.github.io/tags/game/"}]}