Codeforces 902 树同型构造 多项式长除法构造(辗转相除法)
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;
const double eps = 1.0e-6;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//next_permutation
ll mod = 1e9 + ;
int n, aim;
int v[];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out1.txt", "w", stdout);
cin >> n >> aim;
int pa = , pb = ;
v[] = ;
for (int i = ; i <= n; i++)
{
cin >> pa >> pb;
if (!v[pa])
{
cout << "NO" << endl;
exit();
}
for (int j = pa; j <= pb; j++)
{
//cout<<j<<endl;
v[j] = ;
}
if (v[aim])
{
cout << "YES" << endl;
exit();
}
}
cout << "NO" << endl;
}
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 0x3f3f3f3f
//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
int n;
vector<int> tree[];
int anser = ;
int color[];
int aim[];
void dfs(int x, int now)
{
if (now != aim[x])
{
anser++;
now = aim[x];
}
int len = tree[x].size();
for (int i = ; i < len; i++)
{
int to = tree[x][i];
dfs(to, now);
}
}
int main()
{
//freopen("out.txt","w",stdout);
cin >> n;
for (int i = ; i <= n; i++)
{
int now;
cin >> now;
tree[now].pb(i);
}
for (int i = ; i <= n; i++)
{
cin >> aim[i];
}
dfs(, );
cout << anser << 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;
const double eps = 1.0e-6;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//next_permutation
ll mod = 1e9 + ;
int n;
int h[];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out1.txt", "w", stdout);
cin >> n;
int flag = ;
int now = ;
for (int i = ; i <= n + ; i++)
{
scanf("%d", h + i);
if (h[i - ] > && h[i] > )
{
flag = ;
}
}
if (!flag)
{
cout << "perfect" << endl;
}
else
{
cout << "ambiguous" << endl;
for (int i = ; i <= n + ; i++)
{
for (int j = ; j <= h[i]; j++)
{
cout << now << " ";
}
now += h[i];
}
cout << endl;
int flag2 = ;
now = ;
for (int i = ; i <= n + ; i++)
{
if (h[i - ] > && h[i] > && flag2)
{
flag2 = ;
cout << now - <<" ";
for (int j = ; j <= h[i] - ; j++)
{
cout << now << " ";
}
}
else
{
for (int j = ; j <= h[i]; j++)
{
cout << now << " ";
}
}
now += h[i];
}
cout << endl;
}
}
D
要求你给出两个多项式 使得A,B辗转相除N次得到答案(B为0)
仿照斐波那契数列使得Fn=x*Fn-1±Fn-2 后面的±的作用是使得给出的多项式满足系数绝对值不超过1的条件
数组可以滚动
#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 0x3f3f3f3f
//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
int anser[][];
int main()
{
anser[][] = ;
anser[][] = ;
anser[][] = ;
int n;
int aim = ;
cin >> n;
for (int i = ; i <= n; i++)
{
aim ^= ;
for (int j = ; j <= i; j++)
{
anser[aim][j] = (anser[aim][j] + anser[aim ^ ][j - ]) % ;
}
}
cout << n << endl;
for (int i = ; i <= n; i++)
{
cout << anser[aim][i] << " ";
}
cout << endl << n - << endl;
for (int i = ; i < n; i++)
{
cout << anser[aim ^ ][i] << " ";
}
cout << endl;
}
Codeforces 902 树同型构造 多项式长除法构造(辗转相除法)的更多相关文章
- (多项式)因式分解定理(Factor theorem)与多项式剩余定理(Polynomial remainder theorem)(多项式长除法)
(多项式的)因式分解定理(factor theorem)是多项式剩余定理的特殊情况,也就是余项为 0 的情形. 0. 多项式长除法(Polynomial long division) Polynomi ...
- Water Tree CodeForces 343D 树链剖分+线段树
Water Tree CodeForces 343D 树链剖分+线段树 题意 给定一棵n个n-1条边的树,起初所有节点权值为0. 然后m个操作, 1 x:把x为根的子树的点的权值修改为1: 2 x:把 ...
- codeforces 389 D. Fox and Minimal path(构造+思维)
题目链接:https://vjudge.net/contest/175446#problem/J 题解:显然要用最多n个点构成的图要使的得到的最短路条数有1e9次个,显然要有几个数相乘容易想到2的几进 ...
- C++ 构造中调用构造
//构造中调用构造 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; class Point{ ...
- C++基本函数的调用优化(构造、拷贝构造、赋值)
合理的函数可提升时间和空间的利用率 //Test1.h #include<iostream> using namespace std; struct ST { private: int a ...
- New Roads CodeForces - 746G (树,构造)
大意:构造n结点树, 高度$i$的结点有$a_i$个, 且叶子有k个. 先确定主链, 然后贪心放其余节点. #include <iostream> #include <algorit ...
- Subordinates CodeForces - 737C (树,构造)
大意: 求构造一棵树, 每个节点回答它的祖先个数, 求最少打错次数. 挺简单的一个构造, 祖先个数等价于节点深度, 所以只需要确定一个最大深度然后贪心即可. 需要特判一下根的深度, 再特判一下只有一个 ...
- Codeforces 639B——Bear and Forgotten Tree 3——————【构造、树】
Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #386 (Div. 2)G. New Roads [构造][树]
题目链接:G. New Roads 题意:给出n个结点,t层深度,每层有a[i]个结点,总共有k个叶子结点,构造一棵树. 分析: 考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那 ...
随机推荐
- day3_Python基础三
参考:http://www.cnblogs.com/jin-xin/articles/7562422.html 一.数据类型 1.1.int:用于计算,不可变,可哈希 数字主要是用于计算用的: #bi ...
- [flask]jinjia2-模板 url_for的使用
url_for是什么? url_for()用于生成URL的函数,是Flask内置模板的1个全局函数 url_for()用来获取URL,用法和在Python脚本中相同.url_for的参数是视图的端点( ...
- Interface default method介绍
一.introduce interface default method Introduce default methodWrite the default method at interfaceTh ...
- Linux下源码安装MySQL-5.6.25
从mysql-5.5起,mysql源码安装开始使用cmake了,因此我们得先安装cmake,配置安装目录./configure --perfix=/.....的时候和以前的会有些区别. 一.安装cma ...
- VS2013配置curl
http://blog.csdn.net/totodum/article/details/51059380 安装完成之后,要注意url的传值, curl中需要传char*
- 运行RGB-DSLAM的一些报错及处理方法
part 4 报错‘create’ is not a menber of 'CV::FeatureDetector::create(detector.c_str()); 查看opencv版本 修改Cm ...
- dos2unix Linux解决编写脚本出现“%0D
## Linux解决编写脚本出现“%0D”# 安装# yum install -y dos2unix# 然后进行转化一下脚本,将其中的install_mysql.sh换成你的脚本# dos2unix ...
- 红帽学习笔记[RHCSA] 第二周
目录 红帽学习笔记[RHCSA]第二周 环境 第七课[网络配置相关] 在Vmware中添加网卡 将网卡添加到虚拟机上 关于网卡命名规则 配置网络 网络配置命令总结 更改hostname 关于SSH的一 ...
- C语言Ⅰ博客作业03
一. 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-3/homework/8718 我在这个课 ...
- CSS基本样式-文本属性
字体属性 文本属性呢,自我认为就是写文档的一些格式属性,例如:字体颜色,字体加粗,字体大小,字体类型等,而且我们在输出测试用例报告的时候也可以用到这些属性,对测试报告进行优化. <html> ...