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个点。。。