版权声明:原创,未经作者允许禁止转载 https://blog.csdn.net/Mr_wuyongcong/article/details/83213656
前言
开始做四面八方扣来的题
成绩
正题
春思【逆元,等比数列,约数】
更之前一道题一样的:
https://blog.csdn.net/Mr_wuyongcong/article/details/82502158
健美猫【 】
博客链接:
https://blog.csdn.net/Mr_wuyongcong/article/details/83212915
摘果子【树形依赖背包 】
博客链接:
https://blog.csdn.net/Mr_wuyongcong/article/details/83210493
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]);
}
尾声
没了