有一个测试2(day3下)

t1 girl
这个题树一定是树的结点数
环是二,然后乘起来,边数大于点数就成零

#include<cstring>
#include<cstdio>
int n,m;
int f[110000],cnt,t[110000],vis[110000];long long ans=1;
int find (int x){
    return f[x]=f[x]==x?x:find(f[x]);
}
int main(){
    freopen("girl.in","r",stdin);
    freopen("girl.out","w",stdout);

    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) f[i]=i,t[i]=1;
    for(int i=1,x,y;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        int fx=find(x);
        int fy=find(y);
        if(fx==fy&&!vis[fx]) t[fx]=2;
        else if(fx==fy&&vis[fx]) t[fx]=0;
        else if(fx!=fy){
            f[fy]=fx;
            t[fx]+=t[fy];
            t[fy]=0;
        }


    }
    for(int i=1;i<=n;i++)
    if(t[i]){
        ans=(1ll*ans*t[i])%1000000007;
    }

    printf("%d",ans);
}

t2
自己写了80
用乘法原理做的,也没去掉一些比n大的数

好像正解是数位dp

#include<cstdio>
#include<cmath> 
#include<iostream>
#define ll long long
ll n,k;
ll fastpow(ll a,ll w){
    ll ans=1;
    while(w){
        if(w&1)
        ans=ans*a;
        a*=a;
        w>>=1;
    }
    return ans;
}
ll ans;
int main(){
    freopen("endless.in","r",stdin);
    freopen("endless.out","w",stdout);
    scanf("%lld%lld",&n,&k);


        ll t=log(n)/log(k)+0.00001;
        //if(n==fastpow(k,t)) t--;
        ll w=fastpow(k,(t+1)/2);
        ll ww=fastpow(k,t);
        ll i;
        for( i=1;i<=k;i++) 
        if(i*ww>n) break;
        ans=w;
        if((t&1)==0)
         ans*=i;
        printf("%lld",ans);
}

100
每一位都这么搞

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
#define ll long long
ll n,k;
ll ans;
int sum;
int a[100];
ll fastpow(ll a,ll w){
    ll ans=1;
    while(w){
        if(w&1)
        ans=ans*a;
        a*=a;
        w>>=1;
    }
    return ans;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    int tot=0;
    while(n)    a[++tot]=n%k,n/=k;

    if(tot&1){
        for(int i=tot;i>=1;i--)
        if(a[i]){
            if(i&1==0){
                ans+=fastpow(k,i/2);
                break;
            }
            ans+=1ll*a[i]*fastpow(k,i/2);
            if(i==1) ans++;
        }
        cout<<ans;
    }else
        cout<<fastpow(k,tot/2);

    return 0;
}

t3 不会
求了个和交了上去,还有2个点。。。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值