Codeforces 932 数组环构造 树上LCA倍增
A
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e7 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 1e9 + ;
int main()
{
string a;
cin >> a;
string ans;
ans = a;
for (int i = ; i <= a.size(); i++)
{
ans += a[a.size() - i];
}
cout << ans << endl;
return ;
}
B
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e7 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int ans[][];
ll mod = 1e9 + ;
int getans(int x)
{
if (x < )
{
return x;
}
else
{
int cur = ;
while (x > )
{
if (x % != )
{
cur *= x % ;
}
x /= ;
}
return getans(cur);
}
}
int main()
{
for (int i = ; i <= ; i++)
{
int now = getans(i);
for (int j = ; j <= ; j++)
{
ans[i][j] = ans[i - ][j];
}
ans[i][now]++;
}
int q;
cin >> q;
int l, r, k;
for (int i = ; i <= q; i++)
{
scanf("%d %d %d", &l, &r, &k);
cout << ans[r][k] - ans[l - ][k] << endl;
}
return ;
}
C
构造题 要求构造出一个数列满足下列条件
可以看成构造有向图里面的环

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e7 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int ans[][];
ll mod = 1e9 + ;
int main()
{
int n, a, b;
cin >> n >> a >> b;
int x, y;
x = y = -;
int cnt = n / a;
for (int i = ; i <= cnt; i++)
{
if ((n - i * a) % b == )
{
x = i;
y = (n - i * a) / b;
break;
}
}
if (x == -)
{
cout << - << endl;
return ;
}
int cur = ;
for (int i = ; i <= x; i++)
{
cout << cur + a << " ";
for (int j = ; j <= a - ; j++)
{
cout << cur + j << " ";
}
cur += a;
}
for (int i = ; i <= y; i++)
{
cout << cur + b << " ";
for (int j = ; j <= b - ; j++)
{
cout << cur + j << " ";
}
cur += b;
}
//cout << endl;
return ;
}
D
https://www.cnblogs.com/AWCXV/p/8453152.html
https://www.cnblogs.com/forever97/p/cf463.html
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
const int N = 4e5;
const int M = ;
const ll INF = 1e16;
int Q;
ll last, W[N + ], sum[N + ][M + ];
int f[N + ][M + ], cnt = ;
int main()
{
cin >> Q;
for (int i = ; i <= ; i++)
{
sum[][i] = sum[][i] = INF;
}
W[] = INF;
for(int i=;i<=Q;i++)
{
ll ope, p, q;
cin >> ope >> p >> q;
if (ope == )
{
ll R = p ^ last, w = q ^ last;
cnt++;
W[cnt] = w;
if (W[R] >= w)
{
f[cnt][] = R;
}
else
{
ll now = R;
for (int i = ; i >= ; i--)
if (W[f[now][i]] < w)
{
now = f[now][i];
}
f[cnt][] = f[now][];
}
for (int i = ; i <= ; i++)
{
f[cnt][i] = f[f[cnt][i - ]][i - ];
} sum[cnt][] = W[f[cnt][]]; for (int i = ; i <= ; i++)
{
if (f[cnt][i] == )
{
sum[cnt][i] = INF;
}
else
{
sum[cnt][i] = sum[cnt][i - ] + sum[f[cnt][i - ]][i - ];
}
}
}
else
{
ll R = p ^ last, X = q ^ last;
int len = ;
if (X < W[R])
{
cout << << endl;
last = ;
continue;
}
X -= W[R];
len++;
for (int i = ; i >= ; i--)
{
if (X >= sum[R][i])
{
X -= sum[R][i];
R = f[R][i];
len += ( << i);
}
}
cout << len << endl;
last = len;
}
}
return ;
}
Codeforces 932 数组环构造 树上LCA倍增的更多相关文章
- LCA(倍增在线算法) codevs 2370 小机房的树
codevs 2370 小机房的树 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 小机房有棵焕狗种的树,树上有N个节点, ...
- 【codevs2370】小机房的树 LCA 倍增
2370 小机房的树 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 小机房有棵焕狗种的树,树上有N个节点,节点标号为0 ...
- 【BZOJ5304】[HAOI2018]字串覆盖(后缀数组,主席树,倍增)
[BZOJ5304][HAOI2018]字串覆盖(后缀数组,主席树,倍增) 题面 BZOJ 洛谷 题解 贪心的想法是从左往右,能选就选.这个显然是正确的. 题目的数据范围很好的说明了要对于询问分开进行 ...
- CodeVs.2370 小机房的树 ( LCA 倍增 最近公共祖先)
CodeVs.2370 小机房的树 ( LCA 倍增 最近公共祖先) 题意分析 小机房有棵焕狗种的树,树上有N个节点,节点标号为0到N-1,有两只虫子名叫飘狗和大吉狗,分居在两个不同的节点上.有一天, ...
- POJ.1986 Distance Queries ( LCA 倍增 )
POJ.1986 Distance Queries ( LCA 倍增 ) 题意分析 给出一个N个点,M条边的信息(u,v,w),表示树上u-v有一条边,边权为w,接下来有k个询问,每个询问为(a,b) ...
- POJ.1330 Nearest Common Ancestors (LCA 倍增)
POJ.1330 Nearest Common Ancestors (LCA 倍增) 题意分析 给出一棵树,树上有n个点(n-1)条边,n-1个父子的边的关系a-b.接下来给出xy,求出xy的lca节 ...
- 牛客网 桂林电子科技大学第三届ACM程序设计竞赛 D.寻找-树上LCA(树上a到b的路径上离c最近的点)
链接:https://ac.nowcoder.com/acm/contest/558/D来源:牛客网 寻找 小猫在研究树. 小猫在研究树上的距离. 给定一棵N个点的树,每条边边权为1. Q次询问,每次 ...
- LCA(最近公共祖先)——LCA倍增法
一.前人种树 博客:最近公共祖先 LCA 倍增法 博客:浅谈倍增法求LCA 二.沙场练兵 题目:POJ 1330 Nearest Common Ancestors 代码: const int MAXN ...
- POJ - 1330 Nearest Common Ancestors(dfs+ST在线算法|LCA倍增法)
1.输入树中的节点数N,输入树中的N-1条边.最后输入2个点,输出它们的最近公共祖先. 2.裸的最近公共祖先. 3. dfs+ST在线算法: /* LCA(POJ 1330) 在线算法 DFS+ST ...
随机推荐
- Vue 项目构建
一.初始化项目 1.vue init webpack (fileName) 2.项目名称 3.项目描述 4.项目作者 5.是否依赖 .Vue 文件开发 第一个选项可以不依赖 .Vue 文件开发, 第二 ...
- 国内4G频段划分
国内4G频段划分 2015年 4G网络建设如火如荼地进行,换手机大家几乎都买的4G手机,那么看到如下参数怎么知道手机所支持的网络呢? SIM 1:4G TDD-LTE:TD38/39/40/41: ...
- python读取文件时遇到非法字符的处理 UnicodeDecodeError: 'gbk' codec can't decode bytes in position
报错UnicodeDecodeError: 'gbk' codec can't decode bytes in position ipath = 'D:/学习/语料库/SogouC.mini/Samp ...
- python - del 方法
转自:http://blog.csdn.net/love1code/article/details/47276683 python中的del用法比较特殊,新手学习往往产生误解,弄清del的用法,可以帮 ...
- JS实现数组排序:升序和降序
如果指明了 compareFunction ,那么数组会按照调用该函数的返回值排序.即 a 和 b 是两个将要被比较的元素: 如果 compareFunction(a, b) 小于 0 ,那么 a 会 ...
- Navicat Premium Mac 12 破解方法-亲测成功
参照这2篇文档,破解成功了.操作步骤写的很清楚,不再缀述,只记录一下自己破解过程中,认为要注意的点.以免以后再多花时间熟悉重新熟悉操作步骤 Mac安装Navicat(破解版) Navicat Prem ...
- 测开之路一百二十八:flask之重定向和404
a.b两个视图,分别返回a的页面和b的页面 重定向:redirect 重定向到路由:请求/a/时,重定向到/b/ 重定向到视图函数:url_for(“函数名“),访问/a/时,重定向到函数b() 主动 ...
- MariaDB增删改
1.MariaDB 数据类型 MariaDB数据类型可以分为数字,日期和时间以及字符串值. 使用数据类型的原则:够用就行, 尽量使用范围小的,而不用大的 常用的数据类型: 1.整数:int, bit( ...
- web端测试的测试点和注意事项
工作中接触了不同类型的web端系统,内容不同,需求不同,测试关注点也存在些许的不同,但是总体测试思路和关注的点都类似,下面是总结自己所接触的web端系统测试的一些测试点,不尽全面,以后接触新的业务系统 ...
- 【ABAP系列】SAP ABAP MRKO增强
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP MRKO增强 ...