标签:一调 ch 高二上 int long WR 哈希 2022.7 include
感谢没吃晚饭的 $Debuf$ 成功爆炸
T1 耗掉一个小时 T2 耗掉一个小时
谁想到 T3 是个大模拟……思路和题解一样就是没写完恶心死了
A. 匹配
B. 回家
C. 寿司
赛时得分:$300/400$
赛时排行:$Rank2$
又强又可爱的 $Eafoo$ 又是$Rank1$太强了%%%
……有点诡异
那么这个蒟蒻是怎么挂大分的呢?下面就让小编带着大家一起来看看吧(
A. 匹配
这,赛时写了 $KMP$ 然后觉得复杂度不对劲删了……
然后写了一棵 $Trie$ 。100 -> 45。
死活没想过哈希,但理论上 $Trie$ 是能过的……
可能是我写丑了吧
然后赛后10min写了一个哈希过了……
如此模板的哈希,我一定是抽fang了罢(悲
当然哈希不建议用自然溢出,很可能被卡掉
#include<cstdio> #include<cstring> #include<string> #define int long long #define WR WinterRain using namespace std; const int WR=1001000,P=233; int lena,lenb; unsigned long long base[WR]; char a[WR],b[WR]; int read(){ int s=0,w=1; char ch=getchar(); while(ch>'9'||ch<'0'){ if(ch=='-') w=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ s=(s<<3)+(s<<1)+ch-'0'; ch=getchar(); } return s*w; } signed main(){ int t=read(); base[0]=1; for(int i=1;i<WR;i++) base[i]=base[i-1]*(unsigned long long)P; while(t--){ lena=read(); lenb=read(); scanf(" %s",a+1); for(int i=1;i<=lenb;i++) b[i]=a[i]; scanf(" %c",&b[lenb+1]); lenb++; int ans=0; int l=1,r=lenb; unsigned long long hasha=0,hashb=0; while(l<=lena&&r>=1){ hasha=hasha*P+a[l]-'a'; hashb+=(b[r]-'a')*base[lenb-r]; if(hasha==hashb) ans=l; l++,r--; } printf("%lld\n",ans); } return 0; }View Code
这里附上 Eafoo 的 KMP
#include <cstdio> #include <algorithm> #include <cctype> #include <iostream> #include <vector> #include <cmath> using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn = 2e5 + 10; int read() { int x = 0; char c; bool f = 0; while (!isdigit(c = getchar())) { if (c == '-') { f = 1; } } do { x = (x << 1) + (x << 3) + (c ^ 48); } while (isdigit(c = getchar())); if (f) { return -x; } return x; } char getFunc() { char c; while (!isalpha(c = getchar())) { } return c; } template <typename T> void mem(T num, int n) { for (int i = 1; i <= n; ++i) { num[i] = 0; } } int num[maxn]; const int p = 131; int la, lb; char a[maxn], b[maxn], str[maxn]; int f[maxn]; int main() { // 突然发现二分假了,太致命了) // 其实就是要跑个 KMP int T = read(); while (T--) { la = read(), lb = read(); scanf("%s", str + 1); for (int i = 1; i <= la; ++i) { a[i] = str[i]; } for (int i = 1; i <= lb; ++i) { b[i] = str[i]; } b[++lb] = getFunc(); mem(f, max(la, lb)); // printf("a: %s\nb: %s\n", a + 1, b + 1); for (int i = 2, j = 0; i <= la; ++i) { while (a[j + 1] != a[i] && j) { j = f[j]; } if (a[j + 1] == a[i]) { ++j; } f[i] = j; } int j = 0; for (int i = 1; i <= lb; ++i) { while (b[i] != a[j + 1] && j) { j = f[j]; } if (b[i] == a[j + 1] && j < la) { ++j; } } printf("%d\n", j); } }View Code
B. 回家
考试的时候居然先写成了求割边……
然后发现了不对劲(
这个很显然就是求割点……吗?
极其致命的错误:走的点都是割点,但割点不一定要走!!!
这个没什么好说的,没构造出来就是没构造出来……
赛后和 Sakura 大佬讨论了一节生物课……(
#include<cstdio> #include<cstring> #include<string> #include<stack> #define WR WinterRain using namespace std; const int WR=1001000; struct Edge{ int pre,to; }edge[WR]; int n,m; int cnt,maxx,head[WR]; int ipt[WR],low[WR],tot; bool flag[WR],bin[WR]; int read(){ int s=0,w=1; char ch=getchar(); while(ch>'9'||ch<'0'){ if(ch=='-') w=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ s=(s<<3)+(s<<1)+ch-'0'; ch=getchar(); } return s*w; } void clr(){ for(int i=1;i<=n;i++) head[i]=ipt[i]=low[i]=bin[i]=flag[i]=0; cnt=0;tot=1; } void add(int u,int v){ edge[++tot].pre=head[u]; edge[tot].to=v; head[u]=tot; } void tarjan(int u,int e){ low[u]=ipt[u]=++cnt; for(int i=head[u];i;i=edge[i].pre) if(i!=(e^1)){ int v=edge[i].to; if(!ipt[v]){ tarjan(v,i); low[u]=min(low[u],low[v]); flag[u]|=flag[v]; if(ipt[u]<=maxx&&flag[v]&&u!=1&&u!=n) bin[u]=true; }else low[u]=min(low[u],ipt[v]); } if(flag[u]) maxx=min(maxx,low[u]); } int main(){ int t=read(); while(t--){ clr(); n=read(),m=read(); flag[n]=true; maxx=n+1; for(int i=1;i<=m;i++){ int u=read(),v=read(); add(u,v);add(v,u); } tarjan(1,0); int ans=0; for(int i=1;i<=n;i++){ if(bin[i]) ans++; } printf("%lld\n",ans); for(int i=1;i<=n;i++){ if(bin[i]) printf("%lld ",i); } printf("\n"); } return 0; }View Code
C. 寿司
忘了在哪里见过这道题了,学长们一致认为极其毒瘤(是么?我也记不清了
反正我先看到这道题就觉得要坏事,砸了一个小时上去……也没写出来
标签:一调,ch,高二上,int,long,WR,哈希,2022.7,include 来源: https://www.cnblogs.com/WintersRain/p/16459390.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。