ssl提高组周四备考赛【2015.10.18】

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

前言

开始做四面八方扣来的题


成绩

R a n k Rank P e r s o n Person S c o r e Score A A B B C C
1 1 2017 z y c 2017zyc 160 160 70 70 30 30 60 60
2 2 2017 w y c 2017wyc 140 140 80 80 10 10 50 50
3 3 2017 l r z 2017lrz 140 140 40 40 100 100 0 0
4 4 2017 x j q 2017xjq 100 100 70 70 30 30 0 0
5 5 2017 x x y 2017xxy 100 100 70 70 30 30 0 0
6 6 2015 g j h 2015gjh 100 100 0 0 0 0 100 100
7 7 2017 h j q 2017hjq 70 70 40 40 30 30 0 0
8 8 2017 l w 2017lw 70 70 40 40 30 30 0 0
9 9 2015 y j y 2015yjy 70 70 40 40 30 30 0 0
10 10 2015 z y f 2015zyf 70 70 40 40 0 0 30 30

正题


T 1 : n s s l 1194 T1:nssl1194- 春思【逆元,等比数列,约数】

更之前一道题一样的:
https://blog.csdn.net/Mr_wuyongcong/article/details/82502158


T 2 : n s s l 1195 T2:nssl1195- 健美猫【 ? ? ? ???

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


T 3 : n s s l 1196 T3:nssl1196- 摘果子【树形依赖背包 , d p ,dp

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


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


T1 80分code

#include<cstdio>
#include<algorithm>
#define mod 9901
#define ll long long
using namespace std;
ll pr[50],c[50],a,b,cnt,ans;
void prime(ll a)
{
	for(ll i=2;i*i<=a;i++)
	{
		if(!(a%i))
		{
			pr[++cnt]=i;
			while(!(a%i)) c[cnt]++,a/=i;
		}
	}
	if(a!=1) pr[++cnt]=a,c[cnt]=1;
}
ll power(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=(ans*a)%mod;
		a=(a*a)%mod;b>>=1;
	}
	return ans;
}
int main()
{
	scanf("%lld%lld",&a,&b);
	prime(a);
	ans=1;
	for(ll i=1;i<=cnt;i++)
	{
		ll inx=power(pr[i]-1,mod-2);
		if(!inx)
		{
			ans=ans*((c[i]*b+1)%mod)%mod;
			continue;
		}
		ll k=(power(pr[i],c[i]*b+1)+mod-1)%mod*inx%mod;
		ans=ans*k%mod;
	}
	printf("%lld",ans);
}

T2 10分code

#include<cstdio>
#include<algorithm>
#define N 2000010
using namespace std;
int n,s[N*2],ans,sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",&s[i]),s[i+n]=s[i];
	ans=1;
	int i=2;
	while(i<=2*n)
	{
		if(s[i]<s[ans])
		{
			ans=i;
			i++;
			continue;
		}
		if(s[i]>s[ans])
		{
			i++;
			continue;
		}
		int k=1;
		while(i+k<=2*n&&s[i+k]==s[ans+k]) 
		  k++;
		if(i+k>2*n) break;
		if(s[i]>s[i+k])
			ans=i+k;
		else if(s[ans+k]>s[i+k]) 
			ans=i;
		i+=k+1;
	}
	for(i=ans;i<ans+n;i++)
	  sum+=abs(s[i]-(i-ans+1));
	printf("%d",sum);
}

T3 50分code

#include<cstdio>
#include<algorithm>
#define N 2010
using namespace std;
struct node{
	int to,next;
}a[N];
int n,m,v[N],p[N],ls[N],f[N][N],tot,x,y;
void addl(int x,int y)
{
	a[++tot].to=y;
	a[tot].next=ls[x];
	ls[x]=tot;
}
void dp(int x,int fa)
{
	for(int i=ls[x];i;i=a[i].next)
	{
		int y=a[i].to;
		if(y==fa) continue;
		dp(y,x);
		for(int j=m;j>=p[y];j--)
		{
		    for(int k=p[y];k<=j;k++)
			  f[x][j]=max(f[x][j],f[x][j-k]+f[y][k]);
		}
	}
	for(int j=m;j>=p[x];j--)
	  f[x][j]=f[x][j-p[x]]+v[x];
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&v[i],&p[i]);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		addl(x,y);
		addl(y,x);
	}
	dp(1,0);
	printf("%d",f[1][m]);
}

尾声

没了

猜你喜欢

转载自blog.csdn.net/Mr_wuyongcong/article/details/83213656