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]结点,最多能有多少叶子结点 那 ...
随机推荐
- 读取位置 0xcccccccc 时发生访问冲突
XXXXX.exe 中的 0x1004eec2 处有未经处理的异常: 0xC0000005: 读取位置 0xcccccccc 时发生访问冲突 DEBUG模式下总是出现此错误,改为Release模式,错 ...
- Python之异常处理-Exception
在写python程序时, 不要害怕报错, 也不要怕自己的英语不够好, 不要看到一有红色的字就心里发怂. 其实报的错也是有套路可寻滴~识别了异常的种类, 才能对症下药. 常见异常: Exception ...
- 在 vue 中用 transition 实现轮播效果
概述 今天我接到一个需求:轮播效果.本来我是打算使用 Swiper 实现的,但是想起来貌似 transition 也能实现.于是就试了下,真的可以,还挺简单的,于是就记录下来,供以后开发时参考,相信对 ...
- conftest.py作用范围
前言 一个测试工程下是可以有多个conftest.py的文件,一般在工程根目录放一个conftest.py起到全局作用.在不同的测试子目录也可以放conftest.py,作用范围只在该层级以及以下目录 ...
- java:Hibernate框架4(延迟加载(lazy),抓取(fetch),一级缓存,get,load,list,iterate,clear,evict,flush,二级缓存,注解,乐观锁和悲观锁,两者的比较)
1.延时加载和抓取: hibernate.cfg.xml: <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-co ...
- WebLogic下Argument(s) "type" can't be null.
启动项目出现Argument(s) "type" can't be null.异常.异常如下: java.lang.IllegalArgumentException: Argume ...
- C#代码获取另一程序的错误提示,并关闭窗口。
A程序报错弹框如下: B程序捕捉到此错误消息,并关闭.B程序核心代码如下. private void timer_Click(object sender, EventArgs e) { //查找Mes ...
- 报错:java.lang.NoClassDefFoundError: com/google/inject/Injector
使用testng report,导入jar包:reportng.jar和velocity-dep-1.4.jar后,执行脚本,报错如下: 缺少依赖的jar包:guice-4.0.jar 导入依赖的ja ...
- LeetCode.1009-十进制数的补码(Complement of Base 10 Integer)
这是小川的第377次更新,第404篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第238题(顺位题号是1009).每个非负整数N都具有二进制表示.例如,5可以二进制表示为 ...
- CentOS7设置集群环境SSH免密访问
1.准备工作 1)通过克隆或者其他方式获得可互相通信的多台节点(本文为3台虚拟机:hadoop101.hadoop102.hadoop103) 2)配置节点的静态IP.hostname.hosts,参 ...