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]结点,最多能有多少叶子结点 那 ...
随机推荐
- 清空mysql数据
delete from 表名; truncate table 表名; 不带where参数的delete语句可以删除mysql表中所有内容,使用truncate table也可以清空mysql表中所有内 ...
- 关于Oracle报表
1.存储过程中的WHEN OTHERS THEN是什么意思. 异常分很多种类,如NO_FOUND.OTHERS处本应该写异常名称,如果不想把异常分得那么细,可以笼统一点用OTHERS来捕获,即所有异常 ...
- WireShark简单使用以及TCP三次握手
最近一直在用C#编写服务器端的程序,苦于一直找不到合适的方法来测试网络程序,这篇文章很好的解释了网络程序的底层实现. WireShark是最好的学习网络协议最好的工具. wireshark介绍 wir ...
- 阶段3 2.Spring_03.Spring的 IOC 和 DI_5 BeanFactory和ApplicationContext的区别
核心容器的两个接口.ApplicationContext和BeanFactory 怎么知道对象被创建了呢 我们只需要在实现类里面构造函数内打印输出一段话 然后再这里加上一个断点 运行程序,光标停在这个 ...
- git pull 覆盖本地代码
在使用Git的过程中,有些时候我们只想要git服务器中的最新版本的项目,对于本地的项目中修改不做任何理会,就需要用到Git pull的强制覆盖,具体代码如下: $ git fetch --all $ ...
- Redis 常用命令 大全
Redis 常用命令 发现几个很好的 Redis 常用命令汇总大全网页,分享给小伙伴们~ 1.Redis 命令参考 http://redisdoc.com/string/index.html 2.W3 ...
- C#客户端填充外部IE浏览器中网页文本(input)且不提交
//引用COM组件//Microsoft HTML Object Library//Microsoft Internet Controls 记得改成x86 SHDocVw.ShellWindows ...
- c++ 函数后面有个 const
非静态成员函数后面加const,类似如下函数: class testClass{ public: void testClass() const{ /*...*/} private: /*...*/ } ...
- 在Windows服务器安装ss服务端用于逃脱公司行为管理
1.安装:python-2.7.14.amd64.msi 2.配置环境变量 3.Win64OpenSSL-1_0_2n.exe 4.安装ss服务端:pip install **adowsocks 5. ...
- 【计算机视觉】阶编码本模型(Multi phase codebook model)
转自:http://www.cnblogs.com/xrwang/archive/2012/04/24/MPCBBGM.html 多阶编码本模型(Multi phase codebook model) ...