Tasks - AtCoder Beginner Contest 254

D - Together Square

题意: 给定一个N,找出所有不超过N的 ( i , j ),使得( i * j )是一个平方数。

题解: 首先要知道一个数学只是,如果i*j是平方数,那么i*j /(f(i)*f(j))也是平方数  (f(j)表示的是j的不超过j的最大平方数因子),然后因为i/f(i)一定可以被质数 p分割两次或更多,所以得到 i/f(i)=j/f(j))

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=2e5+10;
const ll mod=1e9+7;
vector<ll> p,q;
ll n,t,cnt[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(ll i=1;i*i<=n;i++){
p.push_back(i*i);
}
for(ll i=1;i<=n;i++){
ll f=*(upper_bound(p.begin(),p.end(),i)-1);//找到不超过i的最大的平方数
if(i%f!=0){
ll d=(ll)sqrt(f);
while(i%f!=0){//判断是不是i的因子,不是就减
d--;
f=d*d;
}
}
cnt[i/f]++;
}
ll ans=0;
for(ll i=1;i<=n;i++) ans+=cnt[i]*cnt[i];
cout<<ans;
}

E - Small d and k

题意: 一个无向图,每次询问一个点,与这个点距离不超过k的所有点的权值之和

题解: 暴力即可,注意每次vis的清零,不要用memset全部清零,会tle,可以存储一下所有走过的点,然后最后只将他们清空。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=3e5+5;
const ll mod=998244353;
const ll inf=1e18;
ll n,dp[N],m;
ll cnt,head[N*2],ans,vis[N];
struct ss{
ll next,to;
}e[N*2];
void add(ll x,ll y){
e[++cnt].to=y;
e[cnt].next=head[x];
head[x]=cnt;
}
void bfs(ll beg,ll maxn){
queue<pll> q;
q.push({beg,0});
vis[beg]=1;
vector<ll> sum;
sum.push_back(beg);
while(!q.empty()){
ll l=q.front().first;
ll r=q.front().second;
q.pop();
if(r<=maxn) ans+=l;
else continue;
for(ll i=head[l];i;i=e[i].next){
ll j=e[i].to;
if(!vis[j]) vis[j]=1,sum.push_back(j),q.push({j,r+1});
}
}
for(ll i=0;i<sum.size();i++) vis[sum[i]]=0;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(ll i=1;i<=m;i++){
ll x,y;cin>>x>>y;
add(x,y); add(y,x);
}
ll t;cin>>t;
while(t--){
ll x,y;cin>>x>>y;
ans=0;
bfs(x,y);
cout<<ans<<endl;
}
}

AtCoder Beginner Contest 254(D-E)的更多相关文章

  1. Atcoder Beginner Contest 147C(状态压缩)

    最多15个人,用N个二进制的数字表示每个人的状态,然后检验.这串数字相当于已经把这些人的状态定了下来,如果和输入的情况不符则这串数字不正确,直接忽略,因为枚举了所有的情况,所以总有正确的,不必在错误的 ...

  2. AtCoder Beginner Contest 086 (ABCD)

    A - Product 题目链接:https://abc086.contest.atcoder.jp/tasks/abc086_a Time limit : 2sec / Memory limit : ...

  3. AtCoder Beginner Contest 085(ABCD)

    A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...

  4. AtCoder Beginner Contest 084(AB)

    A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit  ...

  5. AtCoder Beginner Contest 083 (AB)

    A - Libra 题目链接:https://abc083.contest.atcoder.jp/tasks/abc083_a Time limit : 2sec / Memory limit : 2 ...

  6. AtCoder Beginner Contest 264(D-E)

    D - "redocta".swap(i,i+1) 题意: 给一个字符串,每次交换相邻两个字符,问最少多少次变成"atcoder" 题解: 从左到右依次模拟 # ...

  7. Atcoder Beginner Contest 121D(异或公式)

    #include<bits/stdc++.h>using namespace std;int main(){    long long a,b;    cin>>a>&g ...

  8. Atcoder Beginner Contest 156E(隔板法,组合数学)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ; ; long long fac[N] ...

  9. Atcoder Beginner Contest 155E(DP)

    #definde HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; int main(){ ios: ...

随机推荐

  1. Tensor的向量化

    向量化操作是指可以在同一时间进行批量地并行计算,例如矩阵运算,以达到更好效率的一种方式. 尽量使用向量化直接对Tensor操作,避免低效率的for循环对元素逐个操作.

  2. SAP 日期计算

    1. CONVERSION_EXIT_IDATE_OUTPUT     INPUT:      20200601     OUTPUT:   03FEB2008 2. CONVERT_DATE_TO_ ...

  3. UiPath选择器之页面选择器的介绍和使用

    一.页面选择器的介绍 某些软件程序的布局和属性节点具有易变的值,例如某些Web应用程序.UiPath Studio无法预测这些变化,因此,您可能必须手动生成一些选择器. 每个属性都有一个分配的值.选择 ...

  4. 【前端面试】(二)JavaScript加法运算

    视频链接:JavaScript加法运算 - Web前端工程师面试题讲解 数值 + 数值 首先看菜鸟教程有关于数值对象的教程 JavaScript Number 对象 可以知道Infinity , -I ...

  5. bat-静默安装并配置mysql(windows版)

    mysql版本 mysql-5.6.35-winx64 路径关系 @echo off Setlocal enabledelayedexpansion @REM vscode中自动开启延迟环境变量扩展, ...

  6. 数据结构-查找-二叉排序查找(平衡二叉树,B树,B+树概念)

    0.为什么需要二叉排序树 1)数组存储方式: 优点:通过下标访问元素,速度快,对于有序数组,可以通过二分查找提高检索效率: 缺点:如果检索具体某个值,或者插入值(按一定顺序)会整体移动,效率较低: 2 ...

  7. .NET Core 实现后台任务(定时任务)BackgroundService(二)

    原文连接:https://www.cnblogs.com/ysmc/p/16468560.html 在上一篇文档中说到使用 IHostedService 接口实现定时任务,其中,有小伙伴就问到,为什么 ...

  8. 001 Security概述

    1.Spring Security概述 Spring Security是用于解决认证与授权的框架 SpringSecurity默认要求所有的请求都是必须先登录才允许的访问 BCrypt加密算法 BCr ...

  9. 一步一步在angular11中添加多语言支持

    1.新建angular 2.添加@angular/localize ng add @angular/localize 3.设置默认locale_id,在app.module.ts中 import { ...

  10. Javaweb-JSP详解

    一.什么是JSP Java Server Pages:Java服务器端页面,和Servlet一样,用于动态web技术 最大的特点: 写JSP就像在写HTML 区别: HTML只给用户提供静态的数据 J ...