171222 GCD of Polynomials(数学+思维)
来源:互联网 发布:smtp默认端口 编辑:程序博客网 时间:2024/05/16 23:01
Input
You are given a single integer n (1 ≤ n ≤ 150) — the number of steps of the algorithm you need to reach.
Output
Print two polynomials in the following format.
In the first line print a single integer m (0 ≤ m ≤ n) — the degree of the polynomial.
In the second line print m + 1 integers between - 1 and 1 — the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid’s algorithm should perform exactly n steps when called using these polynomials.
If there is no answer for the given n, print -1.
If there are multiple answer, print any of them.
Examples
input
1
output
1
0 1
0
1
input
2
output
2
-1 0 1
1
0 1
Note
In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is
(x2 - 1, x) → (x, - 1) → ( - 1, 0).
There are two steps in it.
注意:
1、审题! 审题! 审题! 读懂题意是做题的基础和关键!
2、理思路
a)为什么 f[i] = x*f[i-1] +/- f[i-2] 是f[i] mod f[i-1] 唯一的分解方式?
b) 递推的关系,该怎么用程序处理比较好?
c) 为什么 +/- 中必有一种方案能使系数的绝对值小于2?
审题! 审题! 审题! !!!!!
#include <bits/stdc++.h>using namespace std;const int maxn = 200;int f[maxn][maxn];int main(){ int n; cin >> n; f[0][0] = 1; f[1][0] = 0; f[1][1] = 1; f[2][0] = -1; f[2][1] = 0; f[2][2] = 1; for(int i = 3; i <= n; i++){ for(int j = i; j > 0; j--) f[i][j] = f[i-1][j-1]; f[i][0] = 0; for(int j = i-2; j >= 0; j--) f[i][j] += f[i-2][j]; bool flag = false; for(int j = 0; j <= i; j++) if(abs(f[i][j]) >= 2){ flag = true;break; // +时不能保证系数为-1, 0, 1 } if(flag) for(int j = 0; j <= i-2; j++) f[i][j] -= 2*f[i-2][j]; } // 输出, 第一个坐标表示最高的次数 cout << n << endl; for(int i = 0; i <= n; i++) cout << f[n][i] << " "; cout << endl; cout << n-1 << endl; for(int i = 0; i <= n-1; i++) cout << f[n-1][i] << " "; cout << endl; return 0;}
- 171222 GCD of Polynomials(数学+思维)
- Codeforces 902 D.GCD of Polynomials 数学,搜索答案
- codeforces 901B GCD of Polynomials (数论+构造)
- HDU 4675 GCD of Sequence(数学)
- HDU 5019 Revenge of GCD(数学)
- HYSBZ-1041 数学思维;GCD 的应用
- Light OJ:1045 Digits of Factorial(数学+思维+对数)
- light-1045 - Digits of Factorial【思维】(数学)
- 【light-oj】-1189 - Sum of Factorials(思维,数学)
- 【CodeForces 804B】Minimum number of steps(思维+数学)
- CodeForces 876B Divisiblity of Differences(思维 + 数学)
- hdoj1772Cake(GCD,数学)
- cf(思维,数学)
- POJ 1722(gcd+思维)
- PAT(甲级)Product of Polynomials (25)
- PAT 1009(甲级) Product of Polynomials
- GCD & LCM (数学基础)
- HDU 4675GCD of Sequence(大组合数取模 容斥原理 组合数学)
- 关于apache2的cgi的配置说明
- 073day(输出前K大的数的解决)
- String字符串对比情况的总结
- 通过“缓存”传递数据,是否可行?
- 如何给ubuntu配置静态IP和DNS
- 171222 GCD of Polynomials(数学+思维)
- HDU 1232 畅通工程
- svn 命令行下常用的几个命令
- HDU2034:人见人爱A-B
- Emacs设置字体
- 关于网站标签页的logo设置
- Java Collection类
- Bug记录 初涉jsp
- Codeforces Testing Round #14 (Unrated) B