bzoj4415-4417:SHOI2013Day1题解

Posted wangyurzee

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj4415-4417:SHOI2013Day1题解相关的知识,希望对你有一定的参考价值。

这场题好弱啊qwq

先发代码再填坑

T1 bzoj4415

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define N 700005

using namespace std;
inline int read(){
	int ret=0;char ch=getchar();
	while (ch<‘0‘||ch>‘9‘) ch=getchar();
	while (‘0‘<=ch&&ch<=‘9‘){
		ret=ret*10-48+ch;
		ch=getchar();
	}
	return ret;
}

int n;
struct BIT{
	int c[N];
	int lowbit(int x){return x&-x;}
	void load(){
		memset(c,0,sizeof(c));
		for (int i=1;i<=n;++i){
			++c[i];
			if (i+lowbit(i)<=n) c[i+lowbit(i)]+=c[i];
		}
	}
	int solve(int sum){
		int x=0,now=0;
		for (int i=(1<<20);i;i=i>>1)
			if (x+i<=n&&now+c[x+i]<sum){
				x+=i;now+=c[x];
			}
		for (int i=(++x);i<=n;i+=lowbit(i)) --c[i];
		return x;
	}
} bit;


int main(){
	n=read();
	bit.load();
	int now=n,sum=n;
	for (int i=n;i;--i){
		int x=read()%i+1;
		if (i-sum>=x) sum=sum+x-1;
		else sum=x+sum-i-1;
		printf("%d\n",bit.solve(sum+1));
	}
	return 0;
}

T2 bzoj4416

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define N 30
#define L 505

using namespace std;
int n,l;char s[L];
int nxt[L][N],dp[1<<21^233];

inline int lowbit(int x){return x&-x;}

bool work(){
	scanf("%d%s",&n,s+1);l=strlen(s+1);
	if (n>21) return 0;
	for (int i=0;i<n;++i) nxt[l+1][i]=l+1;
	for (int i=l;i>=0;--i){
		for (int j=0;j<n;++j) nxt[i][j]=nxt[i+1][j];
		if (i) nxt[i][s[i]-‘a‘]=i;
	}
	for (int i=dp[0]=0;i<(1<<n);dp[++i]=0)
		for (int j=0;j<n;++j)if ((i&(1<<j))>0)
			dp[i]=max(dp[i],nxt[dp[i^(1<<j)]][j]);
	return dp[(1<<n)-1]<=l;
}

int main(){
	int testnumber;scanf("%d",&testnumber);
	while (testnumber--) puts(work()?"YES":"NO");
	return 0;
}

T3 bzoj4417

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define P 30011 

using namespace std;

struct matrix{
	int x,y;
	int a[105][105];
	matrix(){}
	matrix(int _x,int _y):x(_x),y(_y){}
	matrix(int _x){
		x=y=_x;
		memset(a,0,sizeof(a));
		for (int i=1;i<=_x;++i) a[i][i]=1;
	}
} A,B,C,D;

inline matrix operator *(matrix a,matrix b){
	if (a.y!=b.x) swap(a,b);
	matrix ret=matrix(a.x,b.y);
	int z=a.y;
	for (int i=1;i<=ret.x;++i)
		for (int j=1;j<=ret.y;++j){
			ret.a[i][j]=0;
			for (int k=1;k<=z;++k)
				(ret.a[i][j]+=(ll)a.a[i][k]*b.a[k][j]%P)%=P;
		}
	return ret;
}

matrix pow(matrix x,int y){
	matrix ret=matrix(x.x);
	while (y){
		if (y&1) ret=ret*x;
		y/=2;
		x=x*x;
	}
	return ret;
}


int main(){
	int n,m;scanf("%d%d",&n,&m);
	if ((--m)==1){printf("%d\n",n<=2);return 0;}
	A=matrix(2*n);B=matrix(2*n);
	for (int i=1;i<=n;++i)
		for (int j=max(i-1,1);j<=i+1&&j<=n;++j)
			++A.a[j][i+n],++B.a[j+n][i];
	int ans=0;
	if (m&1){
		C=A*B;
		D=B*pow(C,m/2-1);
		ans=D.a[2*n][1];
		D=D*C;
		ans=(D.a[2*n][1]-ans+P)%P;
	}
	else{
		C=A*B;
		D=pow(C,m/2-1);
		ans=D.a[n][1];
		D=D*C;
		ans=(D.a[n][1]-ans+P)%P;
	}
	printf("%d\n",ans);
	return 0;
}

  

以上是关于bzoj4415-4417:SHOI2013Day1题解的主要内容,如果未能解决你的问题,请参考以下文章

SDOI2013 R1 Day2

SDOI2013 R1 Day1

BZOJ 3199: [Sdoi2013]escape

[BZOJ3143][HNOI2013]游走

BZOJ day1

SDOI2017 Round1 Day1 题解 (BZOJ4816 BZOJ4817 BZOJ4818)