1. 程式人生 > 其它 >[考試總結]noip模擬7

[考試總結]noip模擬7

\(\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\huge{\text{菜}}\)

剛開始寫 \(T1\) 的時候,在看到字尾字首之後,直接想到 \(AC\) 自動機,在畫了半個 \(trie\) 樹之後:

\(\huge{\text{這題也配用AC自動機???}}\)


然後秒寫一個 \(hash\),之後一發過樣例,以為穩了。。。

然後。。。

\(freopen\)

還好看到了。。。

不然就暴 \(\color{red}0\) \(\color{green}0\)

\(\color{blue}0\)

似乎 \(kmp\) 也是可以做的,然而我不明白為什麼看到這一題會先想到 \(kmp\) 而不是 \(hash\)。。。

\(code\)



#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
#define debug cout<<"debug"<<endl #define="" int="" long="" file="" *file_eat;="" scan_eat;="" namespace="" xin_io="" {="" freopen="" file_eat="freopen" scanf="" scan_eat="scanf" gc()="" p1="=" p2="" and="" (p2="(p1" =="" buf)="" +="" fread(buf,1,1<<20,stdin),p1="=" p2)="" ?="" eof="" :="" *p1++="" char="" buf[1<<20],*p1="buf,*p2" buf;="" inline="" void="" openfile()="" {freopen("t.txt","r",stdin);}="" outfile()="" {freopen("o.txt","w",stdout);}="" get()="" s="0,f" 1;="" register="" ch="gc();" while(!isdigit(ch))="" if(ch="=" '-')="" f="-1;ch" gc();}="" while(isdigit(ch))="" {s="s" *="" 10="" -="" '0';="" return="" f;="" }="" using="" xin_io;="" static="" const="" maxn="2e5+10;" ull="" unsigned="" xin="" class="" xin_hash="" public:="" h[maxn],p[maxn];="" base;="" xin_hash():="" base(13331){p[0]="1;}" do_hash(char="" *s)="" {for(register="" i="1;s[i];++i)h[i]" h[i-1]="" base="" (s[i]="" 'a'="" 1),p[i]="p[i-1]" base;}="" query(int="" l,int="" r)="" {return="" h[r]="" h[l-1]="" p[r="" l="" 1];}="" }ha,hb;="" t,la,lb;="" a[maxn],b[maxn];="" short="" main()="" #ifndef="" online_judge="" openfile();="" #endif="" scanf("%d",&t);="" while(t--)="" ans="0;" scanf("%d%d",&la,&lb);="" scanf("%s",a+1);="" cout<<a+1<<endl;="" plus;="" cin="">>plus; //cout<<"plus = "<<plus<<endl; for(register="" int="" i="1;i<=lb;++i)" b[i]="a[i];" b[++lb]="plus;" ha.do_hash(a);="" hb.do_hash(b);="" cout<<a[1]<<a[2]<<'="" '<<b[3]<<b[4]<<endl;="" cout<<ha.query(1,1)<<'="" '<<hb.query(4,4)<<endl;="" ms="min(la,lb);" cout<<b[i];="" {="" register="" j="lb" -="" +="" 1;="" if(ha.query(1,i)="=" hb.query(j,lb))="" ans="i;" }="" printf("%d\n",ans);="" return="" 0;="" signed="" main()="" {return="" xin::main();}="" ```="" ----="" #="" t2:="" 衝過="" $t1$="" 之後,然後就開心地去衝="" $t2$了,然後一眼看出="" $tarjan$="" 割點板子。。。。="" 喜提="" $10pts$="" 對於每一個割點,**並不是都是有效割點**,所以,我們只能標記="" **有效割點**,其實只需要在考場程式碼上面加上兩句話:="" ```cpp="" if(pd[y])="" pd[x]="true;" 還有判斷上:="" if((flag=""> 1 or x != 1) and pd[y]) cut[x] = true;

然後就是在 \(tarjan(i)\) 之前加上 pd[n] = true


就這???

  • 真 就這

。。。。

所以你考場上為啥沒想出來???

槓哥的話說,就是 \(\huge{\text{廢*}}\)


別罵了,別罵了。。。。


所以 \(code\)



#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
#define debug cout<<"debug"<<endl #define="" int="" long="" file="" *file_eat;="" scan_eat;="" namespace="" xin_io="" {="" freopen="" file_eat="freopen" scanf="" scan_eat="scanf" gc()="" p1="=" p2="" and="" (p2="(p1" =="" buf)="" +="" fread(buf,1,1<<20,stdin),p1="=" p2)="" ?="" eof="" :="" *p1++="" char="" buf[1<<20],*p1="buf,*p2" buf;="" inline="" void="" openfile()="" {freopen("t.txt","r",stdin);}="" outfile()="" {freopen("o.txt","w",stdout);}="" get()="" s="0,f" 1;="" register="" ch="gc();" while(!isdigit(ch))="" if(ch="=" '-')="" f="-1;ch" gc();}="" while(isdigit(ch))="" {s="s" *="" 10="" -="" '0';="" return="" f;="" }="" using="" xin_io;="" static="" const="" maxn="1e6+10;" ull="" unsigned="" #include<cstring="">
#define m(c,num) memset(c,num,sizeof c)
namespace xin
{
	class xin_edge{public:int next,ver;} edge[maxn<<2];
	int n,m;
	int num;
	int scc_num = 0;
	int dfn[maxn],low[maxn];
	int head[maxn],zhi;
	inline void add(int x,int y)
	{
		edge[++zhi].ver = y; 
		edge[zhi].next = head[x]; head[x] = zhi;
	}
	bool vis[maxn];
	bool cut[maxn];
	bool pd[maxn];
	inline void tarjan(int x)
	{
		dfn[x] = low[x] = ++num;
//		cout<<"x = "<<x<<" dfn[x]="<<dfn[x]<<endl;
		int flag = 0,s = 0;
		for(register int i=head[x];i;i=edge[i].next)
		{
			register int y = edge[i].ver;
			if(!dfn[y])
			{
				tarjan(y);
				low[x] = min(low[x],low[y]);
				if(low[y] >= dfn[x])
				{
					flag++;		
					if((flag > 1 or x != 1) and pd[y]) cut[x] = 1;
				}
				if(pd[y]) pd[x] = 1;
			}
			else low[x] = min(low[x],dfn[y]);//,cout<<low[x]<<' '<<dfn[x]<<endl;
		}
	}
	int T;
	inline void clean()
	{
		num = zhi = 0;
		m(cut,0); m(low,0); m(dfn,0); m(pd,0);
		m(vis,0); m(edge,0); m(head,0); 
	}
	inline short main()
	{
	#ifndef ONLINE_JUDGE
		openfile();// outfile();
	#endif
		T = get();
		for(register int cse=1;cse<=T;++cse)
		{
			clean();
			n = get(); m = get();
			for(register int i=1;i<=m;++i)
			{
				register int x = get(),y = get();
				add(x,y); add(y,x);
			}
			pd[n] = 1;
			for(register int i=1;i<=n;++i)
				if(!dfn[i])
					tarjan(i);
			int cnt = 0;
			for(register int i=2;i<=n-1;++i)
				if(cut[i]) cnt++;//,cout<<" i="<<i<<" cut[i]="<<cut[i]<<endl;
			if(!cnt) {printf(" 0\n\n");continue;}="" printf("%d\n",cnt);="" for(register="" int="" if(cut[i])="" printf("%d="" ",i);="" printf("\n\n");="" clean();="" cout<<(sizeof="" (edge)="" +="" sizeof(cut)="" sizeof(dfn)="" sizeof(low)="" sizeof(vis)="" sizeof(head))="" (1="" <<="" 20)="" <<"mb"<<endl;="" }="" return="" 0;="" signed="" main(){return="" xin::main();}="" ```="" #="" t3:="" 在**以為**自己切掉="" $t2$="" 之後,歡快地去打="" $t3$。。。="" 然後。。。="" **逆序對???**="" 思考一陣子之後,然後陷入了沉思。。。。="" 到了考試結束的時候也沒想出一個所以然來。。。="" 可能是太想打正解了。。。="" 還不如莽一個="" $40pts$="" 的暴力。="" 。。。。。="" ---="" 正解就是維護一個字首和的字首和,對,就這樣。="" 然後二分起點。。。="" 之後就沒啥了。。。="" 所以="" $code$:="" ```cpp="" #include<bits="" stdc++.h="">
using namespace std;
#define int long long 
#define debug cout<<"debug"<<endl file="" *file_eat;="" int="" scan_eat;="" namespace="" xin_io="" {="" #define="" freopen="" file_eat="freopen" scanf="" scan_eat="scanf" gc()="" p1="=" p2="" and="" (p2="(p1" =="" buf)="" +="" fread(buf,1,1<<20,stdin),p1="=" p2)="" ?="" eof="" :="" *p1++="" char="" buf[1<<20],*p1="buf,*p2" buf;="" inline="" void="" openfile()="" {freopen("t.txt","r",stdin);}="" outfile()="" {freopen("o.txt","w",stdout);}="" get()="" s="0,f" 1;="" register="" ch="gc();" while(!isdigit(ch))="" if(ch="=" '-')="" f="-1;ch" gc();}="" while(isdigit(ch))="" {s="s" *="" 10="" -="" '0';="" return="" f;="" }="" using="" xin_io;="" static="" const="" maxn="2e6+10;" m(c,num)="" memset(c,num,sizeof="" c)="" xin="" len,t;="" s[maxn];="" she[maxn],bhe[maxn],brhe[maxn];="" ans;="" random(int="" x)="" {return="" (unsigned)rand()="" rand()="" %="" x;}="" getst(int="" l,int="" r){return="" random(r-2)="" l;}="" srhe[maxn],rhe[maxn];="" query(int="" v,int="" r)="" she[v]="" she[l-1]="" bhe[l-1]="" (rhe[v]-rhe[l-1])="" srhe[v+1]="" srhe[r+1]="" brhe[r+1]="" (rhe[r]="" rhe[v]);}="" bool="" pan(int="" num)="" double="" every="(1.175" ((1.0="" t)))="" 1.0="" num;="" cout<<every<<endl;="" tim="((double)clock()" (double)(clocks_per_sec));="" if(tim="">= every) return false;
		return true;
	}
	bool vis[maxn];
	int num[maxn];
	inline short main()
	{
		#ifndef ONLINE_JUDGE
			openfile();
		#endif
		scanf("%lld",&T);
		for(register int cse=1;cse<=T;++cse)
		{
			register int cnt = 1;
		    scanf("%s",s+1); ans = 0x7f7f7f7f7f7f7f7f;
		    len = strlen(s+1);
		    for(register int i=1;i <= len;i++) s[i + len] = s[i];
		    for(register int i=1;i <= (len * 2);i++)
		    {
		        bhe[i] = bhe[i-1]; she[i] = she[i-1]; rhe[i] = rhe[i-1];
		        if(s[i] == 'R') bhe[i]++;
		        else rhe[i] ++,she[i] += bhe[i];
//				cout<<"bhe[i] = "<</endl></x<<"></endl></stack></queue></algorithm></cmath></cstdio></cstdlib></iostream></plus<<endl;></endl></queue></algorithm></cmath></cstdio></cstdlib></iostream>