ssl提高組週一備考賽【2018.10.27】
阿新 • • 發佈:2018-12-18
前言
想去德育基地…
成績
正題
【】
【點分治平衡樹】
【數論】
T2 60分code
#include<cstdio>
#include<algorithm>
#define N 100010
using namespace std;
struct line{
int to,w,next;
}a[N*2];
int ls[N],tot,n,s,e,x,y,w,mins;
void addl(int x,int y,int w)
{
a[ ++tot].to=y;a[tot].w=w;
a[tot].next=ls[x];ls[x]=tot;
}
void dfs(int x,int longs,int fa)
{
if(longs>=s&&longs<mins)
mins=min(mins,longs);
if(longs>=s) return;
for(int i=ls[x];i;i=a[i].next)
if(a[i].to!=fa)
dfs(a[i].to,longs+a[i].w,x);
}
int main()
{
scanf("%d%d%d",&n,&s,&e);
for(int i=1;i<n;i++)
{
scanf("%d%d%d",&x,&y,&w);
addl(x,y,w);addl(y,x,w);
}
mins=e+1;
for(int i=1;i<=n;i++)
dfs(i,0,0);
if(mins==e+1) printf("-1");
else printf("%d",mins);
}
T3 60分code
#include<cstdio>
#include<algorithm>
using namespace std;
int n,s;
int gcd(int x,int y)
{
return (!y)?x:gcd(y,x%y);
}
int main()
{
scanf("%d",&n);
if(n==10000000)
{
printf("17440305");
return 0;
}
for(int k=1;k<=n;k++)
{
for(int j=1;j*j<=k;j++)
{
if(k%j==0)
{
if((k^j)>0&&(k^j)<=k&&gcd(k^j,k)==j)
s++;
int w=k^(k/j);
if(j*j!=k&&w>0&&w<=k&&gcd(w,k)==(k/j))
s++;
}
}
}
printf("%d",s);
}
尾聲
話說題目還真叫ABC