B. super_log

题意:研究一下就是求幂塔函数 %m的值。

思路:扩展欧拉降幂。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + ;
int a, b, m;
ll eular(ll n)
{
ll ans = n;
for(int i = ;i * i <= n;i++)
{
if(n % i == )
{
ans -= ans / i;
while(n % i == ) n /= i;
}
}
if(n != ) ans -= ans / n;
return ans;
}
int ksm(ll a, ll n, ll mod)
{
if(n == ) return ;
if(a <= ) return a;
if (n == )
return ;
if (a<=)
return a;
bool flag = false;
ll t = ;
for (int i = ; i < n; i++)
{
t = t*a;
if (t >= mod)
{
flag = true;
break;
}
}
ll ans = ;
while (n)
{
if (n & )
{
ans *= a;
ans %= mod;
}
a = a * a % mod;
n >>= ;
}
if (flag)
{
ans += mod;
}
return ans;
}
ll dfs(int a,int b,ll mod)
{
if (b == )
return ;
if (b == )
return a;
if (mod == )
return ;
ll h1 = ksm(a, dfs(a, b-, eular(mod)),mod);
return h1;
}
int main()
{
int t;
cin >>t;
while(t--)
{
cin >> a >> b >> m;
cout << dfs(a, b, m) % m << endl;
}
return ;
}

F. Greedy Sequence

题意:题意好绕的啊,自己看吧。

思路:用线段树查询区间最大值,因为对于每个数 i,只有比他小的数才有用,所以从小到大枚举,在线段树中(此时所有值都小于 i )。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define lr2 (l + r) / 2
const int maxn = 1e5+ ;
int n, k, a[maxn], pos[maxn];
int ans[maxn];
int sum[maxn* ] ;
void up(int rt){
sum[rt] = max(sum[ls], sum[rs]);
}
void build(int l ,int r, int rt)
{
sum[rt] = ;
if(l == r) return ;
int m = lr2;
build(lson);
build(rson);
up(rt);
}
int query(int a, int b, int l, int r, int rt)
{
if(a <= l && b >= r) return sum[rt];
int ans = ;
int m = lr2;
if(a <= m) ans = max(ans,query(a, b, lson));
if(b > m) ans = max(ans, query(a, b, rson));
return ans;
}
void update(int k, int v, int l, int r, int rt)
{
if(l == r){
sum[rt] = v;
return;
}
int m = lr2;
if(k <= m) update(k, v, lson);
else update(k, v, rson);
up(rt);
}
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
cin >> n >> k;
for(int i = ;i <= n;i++){
cin >> a[i];
pos[a[i]] = i;
}
build(, n, );
for(int i = ;i <= n;i++)
{
int l = max(, pos[i] - k);
int r = min(n, pos[i] + k);
int x = query(l, r , , n, );
update(pos[i], i, , n, );
ans[i] = ans[x] + ;
}
for(int i = ;i <= n;i++){
cout << ans[i];
if(i == n)cout << endl;
else cout << " ";
}
}
return ;
}

H. Holy Grail

题意:给你一张n点m边的有向图,无重边,无负加权循环。请你加6对顶点,请你加6条权值最小的边使之没有负圈。

思路:每给一对顶点,跑一遍最短路,没有负环的条件是没有一条来的路和加的边加起来为负,所以每次加的边和答案为反向最短路。

AC代码:

 #include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1e5+;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef pair<ll,int> P;
int n,m;
struct edge{
int to;
ll cost;
}es[maxn];
vector <edge> G[maxn];
ll d[maxn];
void dijkstra(int s)
{
priority_queue<P,vector<P>,greater<P> > que;
fill(d,d+m+,INF);
d[s] = ;
que.push(P(,s));
while(!que.empty())
{
P p= que.top();que.pop();
int v = p.second;
if(d[v] < p.first) continue;
for(int i = ;i < G[v].size();i++)
{
edge e = G[v][i];;
if(d[e.to] > d[v] + e.cost)
{ d[e.to]= d[v] + e.cost;
que.push(P(d[e.to],e.to));
}
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie();std::cout.tie();
int t;
cin >> t;
while(t--)
{
cin >> n >> m;
for(int i = ;i <= n;i++)G[i].clear();
int count = ;
int a,b,c;
for(int i = ;i < m;i++)
{
cin >> a >> b >> c;
es[count].to = b;
es[count].cost = c;
G[a].push_back(es[count++]);
}
for(int i = ;i < ;i++){
cin >> a >> b;
dijkstra(b);
cout << -d[a] << endl;
es[count].to = b;
es[count].cost = -d[a];
G[a].push_back(es[count++]);
} } return ;
}

The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)的更多相关文章

  1. The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解

    (施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出 ...

  2. [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)

    >传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...

  3. 计蒜客 The Preliminary Contest for ICPC Asia Nanjing 2019

    F    Greedy Sequence You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each  ...

  4. The Preliminary Contest for ICPC Asia Nanjing 2019

    传送门 A. The beautiful values of the palace 题意: 给出一个\(n*n\)的矩阵,并满足\(n\)为奇数,矩阵中的数从右上角开始往下,类似于蛇形填数那样来填充. ...

  5. The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail

    题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...

  6. The Preliminary Contest for ICPC Asia Nanjing 2019 B. super_log (广义欧拉降幂)

    In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For examp ...

  7. 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019

    题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...

  8. B.super_log(The Preliminary Contest for ICPC Asia Nanjing 2019)

    同:https://www.cnblogs.com/--HPY-7m/p/11444923.html #define IOS ios_base::sync_with_stdio(0); cin.tie ...

  9. H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...

随机推荐

  1. HTML5: HTML5 新元素

    ylbtech-HTML5: HTML5 新元素 1.返回顶部 1. HTML5 新元素 自1999年以后HTML 4.01 已经改变了很多,今天,在HTML 4.01中的几个已经被废弃,这些元素在H ...

  2. Windows-右键菜单添加选项

    新建 add.reg 输入选项名和选项对应程序路径 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\选项名] [HKEY ...

  3. 解决(Oracle)ORA-12528: TNS: 监听程序: 所有适用例程都无法建立新连接 问题

    解决(Oracle)ORA-12528: TNS: 监听程序: 所有适用例程都无法建立新连接 问题通过在CMD下用lsnrctl status 查看出的问题:发现BLOCKEDORACLE启动步骤:s ...

  4. 使用Pandas读取大型Excel文件

    import os import pandas as pd HERE = os.path.abspath(os.path.dirname(__file__)) DATA_DIR = os.path.a ...

  5. Spring学习笔记(1)——初识Spring

    一.Spring是什么       通常说的Spring其实指的是Spring Framework,它是Spring下的一个子项目,Spring围绕Spring Framework这个核心项目开发了大 ...

  6. shell位置参数和 shift 命令

  7. Stm32CubeMX5 配置 STM32的串口DMA接受方式 --- 基于 stm32f051k8u6

     实现的功能: 使用MDA方式把串口接受的数据在发送给串口(当然也可以做其他解析控制使用) 1. 先初始化 时钟使用外部的晶振配置系统时钟为48Mhz 2. 串口参数配置 3. 使能中断 4. 配置串 ...

  8. zabbix生产环境案例(三)

    生产环境案例(三) 链接:https://pan.baidu.com/s/1q5YwJMTcZLcS5OQ0iOu44A 提取码:8gdi 复制这段内容后打开百度网盘手机App,操作更方便哦 1. Z ...

  9. jquery控件-实现自定义样式的弹出窗口和确认框(转)

    (function () { $.MsgBox = { Alert: function (title, msg) { GenerateHtml("alert", title, ms ...

  10. Qt 【tableview+delegate list越界 ,删除了list,model上还有存在delegate】

    bug如图所示: 模型是n*4  ,因为是越界了每次最后一行点击都会出现这样的 警告,在控制台显示以下,然后程序崩溃. ASSERT failure in Qlist<T>::operat ...