[计蒜客] ACM-ICPC 2019 南京赛区网络预赛 | 部分题解 | 线段树 + 线性筛 + 最短路(下)

简介: J. Nanjing Sum题目描述输入输出样例输入样例输出提示L. Magical Girl Haze题目描述输入输出样例输入样例输出题意:

J. Nanjing Sum


题目描述


A square-free integer is an integer which is indivisible by any square number except 1. For example, 6 = 2·3 is square-free, but 12 = 22·3 is not, because 22 is a square number. Some integers could be decomposed into product of two square-free integers, there may be more than one decomposition ways. For example, 6 = 1·6=6·1=2·3=3·2, n=ab and n=ba are considered different if a≠b. f(n) is the number of decomposition ways that n=ab such that a and b are square-free integers. The problem is calculating

.ca795bb632c94a95a4f5b9d6acc86dbd.png


输入


The first line contains an integer T(T≤20), denoting the number of test cases. For each test case, there first line has a integer n(n≤2·107).


输出


ca795bb632c94a95a4f5b9d6acc86dbd.png

For each test case, print the answer

.

样例输入


2
5
8


样例输出


8
14


提示


cc43513049a04385a4dd157e67d441a2.png=f(1)+⋯+f(8)=1+2+2+1+2+4+2+0=14


素数的f()一定是2

如果说对一个数x进行唯一分解之后,其某一项的指数≥ 3,那么说这个f()值一定是0

n=p1e1x ,则有

b893b6c69ef54aef9147645c041e85ee.png

为什么哩,因为如果 e1 = 2,那么对于 n ,pe1 的贡献就只有 1,p21= p 1 ⋅ p 1 ,所以 f ( p21) = 1 ,而当 e 1 = 1 时,贡献为2 ,因为此时p1 为质数, f ( p1 ) = 2 ,但是得同时保证 x和pe1 1没有大于x 和pe11没有大于1 的共同因子.


最后前缀和一下就可以完成了

可以参考:博客

bool vis[maxn];
int cnt = 0;
int Pri[maxn];
ll f[maxn];
void _Get_Prime(int lim) {
    f[1] = 1LL;
    for (ll i = 2; i <= lim; i++) {
        if (vis[i] == 0) {
            Pri[++cnt] = i;
            f[i] = 2;///prime
        }
        for (ll j = 1; j <= cnt; j++) {
            ll val = i * Pri[j];
            if(val > lim) break;
            vis[val] = 1;
            if (i % Pri[j]) f[val] = f[i] * f[Pri[j]];
            else if(i % (Pri[j] * Pri[j]) == 0) {
                f[val] = 0;
            } else {
                f[val] = f[val / (Pri[j] * Pri[j])];
                break;
            }
        }
    }
}
int main() {
    _Get_Prime(20000000);
    for(int i=1; i<=20000000; i++) {
        f[i] += f[i-1];
    }
    int _ = read;
    while(_ --) {
        ll x = read;
        printf("%lld\n",f[x]);
    }
    return 0;
}
/**
**/


L. Magical Girl Haze


题目描述


There are N cities in the country, and M directional roads from u to v(1<=u, v<=n).Every road has a distance ci. Haze is a Magical Girl that lives in City 1, she can choose no more than K roads and make their distances become 0. Now she wants to go to City N, please help her calculate the minimum distance.


输入


The first line has one integer T(1<=T<=5), then following T cases.

For each test case, the first line has three integers N, M and K. Then the following M lines each line has three integers, describe a road, Ui, Vi, Ci. There might be multiple edges between u and v.

It is guaranteed that N<=100000, M<=200000, K<=10, 0<=c[i]<=1e9. There is at least one path between City 1 and City N.


输出


For each test case, print the minimum distance.


样例输入


1
5 6 1
1 2 2
1 3 4
2 4 3
3 4 1
3 5 6
4 5 2


样例输出


3


题意:


从可以将图中不超过k条有向边的边权设置为0,然后问从1到n的最短路径是多少

可以用分层图最短路来实现

const int maxn=5e6+7;
const int inf=0x3f3f3f3f;
int T,n,m,k;
int tot,head[maxn];
ll d[maxn];
bool f[maxn];
struct edge{    int to,next,w;  }e[maxn];
struct node{
    int dis,u;
    node(int dis,int u):dis(dis),u(u){};
    bool operator<(const node &t)const{  return dis>t.dis;    }
};
void add(int u,int v,int w){
    e[++tot].w=w;   e[tot].to=v;
    e[tot].next=head[u];    head[u]=tot;
}
void dij(){
    priority_queue<node>q;
    memset(f,0,sizeof(f));  memset(d,inf,sizeof(d));
    d[0]=0;
    q.push(node(0,0));
    while(!q.empty()){
        node x=q.top(); q.pop();
        int u=x.u,dis=x.dis;
        if(f[u])    continue;   f[u]=1;
        for(int i=head[u];i;i=e[i].next){
            int y=e[i].to;
//          cout<<y<<endl;
            if(d[y]>d[u]+e[i].w){
                d[y]=d[u]+e[i].w;
                q.push(node(d[y],y));
            }
        }
    }
}
int main(){
    T=read();
    while(T--){
        n=read();   m=read();   k=read();
        memset(head,0,sizeof(head));    tot=0;
        while(m--){
            int u,v,w;
            u=read()-1; v=read()-1; w=read();
            for(int i=0;i<=k;i++){
                add(u*(k+1)+i,v*(k+1)+i,w);
                if(i<k)  add(u*(k+1)+i,v*(k+1)+i+1,0);
            }
        }
        dij();
        int sum=inf;
        for(int i=0;i<=k;i++)    sum=min(1ll*sum,d[(n-1)*(k+1)+i]);
        cout<<sum<<endl;
    }
}
/*
1
5 6 1
1 2 2
1 3 4
2 4 3
3 4 1
3 5 6
4 5 2
*/






目录
相关文章
|
人工智能 BI 网络架构
[计蒜客] ACM-ICPC 2018 南京赛区网络预赛 | 部分题解 | 线段树 + 线性筛 + 最短路(上)
E. AC Challenge 题目描述 输入 输出 样例输入 样例输出 提示 题意: A. An Olympian Math Problem G. Lpl and Energy-saving Lamps 题目描述 输入 输出 样例输入 样例输出 提示 ac_code:
137 0
[计蒜客] ACM-ICPC 2018 南京赛区网络预赛 | 部分题解 | 线段树 + 线性筛 + 最短路(上)
|
11天前
|
机器学习/深度学习 缓存 监控
linux查看CPU、内存、网络、磁盘IO命令
`Linux`系统中,使用`top`命令查看CPU状态,要查看CPU详细信息,可利用`cat /proc/cpuinfo`相关命令。`free`命令用于查看内存使用情况。网络相关命令包括`ifconfig`(查看网卡状态)、`ifdown/ifup`(禁用/启用网卡)、`netstat`(列出网络连接,如`-tuln`组合)以及`nslookup`、`ping`、`telnet`、`traceroute`等。磁盘IO方面,`iostat`(如`-k -p ALL`)显示磁盘IO统计,`iotop`(如`-o -d 1`)则用于查看磁盘IO瓶颈。
|
5天前
|
网络协议 算法 Linux
【Linux】深入探索:Linux网络调试、追踪与优化
【Linux】深入探索:Linux网络调试、追踪与优化
|
1天前
|
Ubuntu 网络协议 Linux
|
2天前
|
JSON 网络协议 Linux
Linux ip命令:网络的瑞士军刀
【4月更文挑战第25天】
8 1
|
3天前
|
缓存 网络协议 Linux
Linux 网络命令大全,详细归纳!
【4月更文挑战第24天】
24 3
Linux 网络命令大全,详细归纳!
|
4天前
|
网络协议 JavaScript Linux
Linux常用网络指令(下)
Linux常用网络指令(下)
12 0
|
4天前
|
Linux
Linux常用网络指令(上)
Linux常用网络指令(上)
6 0
|
4天前
|
安全 Linux 网络安全
【专栏】Linux 网络扫描工具:nmap,涨知识的时间到了!
【4月更文挑战第28天】nmap, 开源网络扫描工具,用于探测主机、网络信息,包括开放端口、服务类型、OS等。本文分三部分介绍:1) nmap简介与基本原理;2) 使用方法和高级技巧,如脚本扩展;3) 实际应用,如网络安全评估、系统管理和渗透测试。学习nmap需注意合规性,持续探索新技巧,以提升网络管理与安全能力。一起开始nmap的探索之旅吧!
|
4天前
|
安全 网络协议 Linux
【专栏】一文教你玩转 Linux 的 ping 命令,从此成为 Linux 网络高手
【4月更文挑战第28天】本文详细介绍了Linux系统中ping命令的使用,包括其基本语法、输出信息、常用参数及高级用法。通过ping,用户可测试网络连通性、诊断故障及评估性能。此外,文章还讨论了ping在不同协议、模拟网络环境及与其他命令结合使用时的场景。注意防火墙和网络环境可能影响ping结果,理解错误信息有助于网络问题排查。熟练掌握ping命令,能助你成为Linux网络专家。不断学习和实践,提升网络技能,为构建稳定网络环境贡献力量。