欢乐纪中某B组赛【2019.1.21】

版权声明:原创,未经作者允许禁止转载 https://blog.csdn.net/Mr_wuyongcong/article/details/86577928

前言

成功翻车


成绩

R a n k Rank 是有算别人的

R a n k Rank P e r s o n Person S c o r e Score A A B B C C
14 14 2017 h z b 2017hzb 80 80 30 30 0 0 50 50
14 14 2017 w y c 2017wyc 80 80 0 0 30 30 50 50
14 14 2017 x x y 2017xxy 80 80 30 30 0 0 50 50
44 44 2017 l w 2017lw 30 30 30 30 0 0 0 0
44 44 2017 l r z 2017lrz 30 30 30 30 0 0 0 0
44 44 2017 z y c 2017zyc 30 30 0 0 30 30 0 0
44 44 2017 h j q 2017hjq 30 30 0 0 0 0 30 30
61 61 2017 x j q 2017xjq 0 0 0 0 0 0 0 0

正题


T 1 : j z o j 4208 T1:jzoj4208- 线段树什么的最讨厌了【 d f s dfs

博客链接:
https://blog.csdn.net/Mr_wuyongcong/article/details/86577063


T 2 : j z o j 4209 T2:jzoj4209- 已经没有什么好害怕的了【差分】

博客链接:
https://blog.csdn.net/Mr_wuyongcong/article/details/86577360


T 3 : j o z j 4010 T3:jozj4010- 我才不是萝莉控呢【哈夫曼树】

博客链接:
https://blog.csdn.net/Mr_wuyongcong/article/details/86577658


s o m e   o f   c o d e some\ of\ code


T2暴力

#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const ll XJQ=1e9+7;
char s[1001];
ll n,ans[1001],sum,t;
int main()
{
	freopen("data.in","r",stdin);
	freopen("data.ans","w",stdout);
	scanf("%lld",&t);
	while(t--){
	scanf("%s",s+1);
	n=strlen(s+1);
	memset(ans,0,sizeof(ans));sum=0;
	for(ll i=1;i<n;i++)
	{
		for(ll j=i+1;j<=n;j++)
		{
			ll left=0;bool flag=1;
			for(ll k=i;k<=j;k++)
			{
			  	if(s[k]=='(') left++;
			  	else left--;
				if(left<0){
					flag=0;
					break;
				}
			}
			if(flag&&!left)
			  for(ll k=i;k<=j;k++)
			    ans[k]++;
		}
	}
	for(ll i=1;i<=n;i++)
	  sum+=ans[i]*i%XJQ;
	printf("%lld\n",sum);
	}
}


T2随机数据

#include<cstdio>
#include<cstdlib>
#include<ctime>
using namespace std;
int t,n;
int main()
{
	freopen("data.in","w",stdout);
	srand(time(0));
	t=10;
	n=100;
	printf("10\n");
	for(int i=1;i<=t;i++)
	{
		//for(int j=1;j<=n/2;j++)
		 // printf("(");
		for(int j=1;j<=n;j++)
		 // printf(")");
		  if(rand()&1) printf(")");
		  else printf("(");
		printf("\n");
	}
}


T2 30code

#include<cstdio>
#include<cstring>
#include<stack>
#define ll long long
using namespace std;
const ll N=1e6+10,XJQ=1e9+7;
stack<ll> left,mark,k;
ll t,n,ans,sum[N],ks,marks;
char s[N];
int main()
{
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%s",s+1);
		n=strlen(s+1);
		ks=0;ans=0;marks=0;
		while(!left.empty()) left.pop();
		while(!mark.empty()) mark.pop();
		while(!k.empty()) k.pop();
		for(ll i=1;i<=n;i++)
		{
			sum[i]=sum[i-1]+i;
			if(s[i]==')'&&left.empty())
				marks=ks=0;
			else if(s[i]==')'){
				ll z=(sum[i]-sum[left.top()-1])%XJQ;
				left.pop();
				marks=mark.top();mark.pop();
				ks=k.top();k.pop();ks=(ks+1)%XJQ;
				(marks+=z*ks)%=XJQ;
				(ans+=marks)%=XJQ;
			}
			else{
				left.push(i);
				mark.push(marks);
				k.push(ks);
				marks=0;ks=0;
			}
		}
		printf("%lld\n",ans);
	}
}

T3 50分code

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e3+10;
int t,n,a[N],f[N][N*2];
int main()
{
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		a[n+1]=0;
		for(int i=n;i>=1;i--)
			scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)
			a[i]+=a[i-1];
		memset(f,0x3f,sizeof(f));
		f[0][0]=0;
		for(int i=1;i<=n;i++)
		{
		  for(int j=n;j>=1;j--)
		    f[i][j]=min(min(f[i][j*2-1],f[i][j*2])+a[i],f[i-1][j-1]);
		}
		printf("%d\n",f[n][1]);
	}
}

总结

开心,题目难一点就翻车了 Q V Q QVQ
T 1 : T1: 好像是 d f s dfs ,就写了一个,然后发现有一个地方直接写了 r e t u r n   0 return\ 0
愉快爆蛋。
T 2 : T2: 写了半天,和正解檫肩而过,写了一个先加后 m o d mod 就愉快30 ,不如暴力 QVQ$
T 3 : T3: 明显 50 50 d p dp
Q V Q V Q QVQVQ

猜你喜欢

转载自blog.csdn.net/Mr_wuyongcong/article/details/86577928
今日推荐