码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj4415-4417:SHOI2013Day1题解

时间:2016-03-08 00:02:41      阅读:729      评论:0      收藏:0      [点我收藏+]

标签:

这场题好弱啊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题解

标签:

原文地址:http://www.cnblogs.com/wangyurzee7/p/5252312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!