POJ2527+多项式除法
模拟一遍即可。
注意一些特殊情况,见代码。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std; const int maxn = ; struct Ploy{
int cnt;//项的数目
int coe[ maxn ];//各项系数
int exp[ maxn ];//各项指数
}a;
struct Ploy2{
int coe1,coe2;
int exp1,exp2;
}b;
struct Ploy3{
int coe,exp;
}tmp; bool Judge( int aim ){
//bool f = false;
for( int i=a.cnt-;i>=;i-- ){
if( a.coe[i]!=&&a.exp[i]>=aim ){
//f = true;
return true ;
}
}
return false;
} void solve( int n,int k ){
//ans.cnt = 0;
while( ){
//if( Judge(k)==false ) break;
int i;
for( i=a.cnt-;i>=;i-- ){
if( a.coe[i]!= ){
tmp.coe = a.coe[i];
tmp.exp = a.exp[i];
break;
}
}
if( tmp.exp<k ) break;
int delta_exp = tmp.exp-k;
int delta_coe = tmp.coe;//商
b.exp1 = tmp.exp,b.coe1 = tmp.coe;
b.exp2 = delta_exp,b.coe2 = delta_coe;
//bool f1 = false,f2 = false;
for( int i=;i<a.cnt;i++ ){
if( a.exp[i]==b.exp1 ){
a.coe[i] -= b.coe1;
//f1 = true;
}
if( a.exp[i]==b.exp2 ){
a.coe[i] -= b.coe2;
//f2 = true;
}
}
}
} int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,k;
while( scanf("%d%d",&n,&k)== ){
if( n==k&&k==- ) break;
a.cnt = ;
for( int i=;i<=n;i++ ){
a.cnt ++;
scanf("%d",&a.coe[i]);
a.exp[i] = i;
}
if( k== ){
puts("");
continue;
}
//printf("input\n");
bool f = false;
for( int i=;i<a.cnt;i++ ){
if( a.coe[i]!= ){
f = true;
break;
}
}
if( f==false ) {
puts("");
continue;
}//多项式全为0
if( k>n ){
for( int i=;i<a.cnt;i++ ){
if( i== ) printf("%d",a.coe[i]);
else printf(" %d",a.coe[i]);
}
printf("\n");
continue;
}//商为0
//printf("solve\n");
solve( n,k );
f = false;
for( int i=;i<a.cnt;i++ ){
if( a.coe[i]!= ){
f = true;
break;
}
}
if( f==false ) {
puts("");
continue;
}//刚好整除
int pos = a.cnt-;
for( int i=a.cnt-;i>=;i-- ){
if( a.coe[i]!= ){
pos = i;
break;
}
}
for( int i=;i<=pos;i++ ){
if( i== ) printf("%d",a.coe[i]);
else {
printf(" %d",a.coe[i]);
}
}
printf("\n");
}
return ;
}
POJ2527+多项式除法的更多相关文章
- Re.多项式除法/取模
前言 emmm又是暂无 前置 多项式求逆 多项式除法/取模目的 还是跟之前一样顾名思义] 给定一个多项式F(x),请求出多项式Q(x)和R(x),满足F(x)=Q(x)∗G(x)+R(x),R项数小于 ...
- P4512 【模板】多项式除法
思路 多项式除法板子 多项式除法 给出\(A(x)\)和\(B(x)\),求一个\(n-m\)次的多项式\(D(x)\),一个\(m-1\)次多项式\(R(x)\),满足 \[ A(x)=B(x)D( ...
- xdoj-1211 (尧老师要教孩子解方程) :多项式除法
想法: 1 由于所有a[i] 是不为0的整数 所以解x是整数 2 其次解是an的约数 3 分解a[n] 用多项式除法判断约数是否为整式的解 #include<cstdio> #includ ...
- 【Codechef】Random Number Generator(多项式除法)
题解 前置技能 1.多项式求逆 求\(f(x)\*g(x) \equiv 1 \pmod {x^{t}}\) 我们在t == 1时,有\(f[0] = frac{1}{g[0]}\) 之后呢,我们倍增 ...
- 洛谷.4512.[模板]多项式除法(NTT)
题目链接 多项式除法 & 取模 很神奇,记录一下. 只是主要部分,更详细的和其它内容看这吧. 给定一个\(n\)次多项式\(A(x)\)和\(m\)次多项式\(D(x)\),求\(deg(Q) ...
- [洛谷P4512]【模板】多项式除法
题目大意:给定一个$n$次多项式$F(x)$和一个$m$次多项式$G(x)$,请求出多项式$Q(x),R(x)$,满足: 1. $Q(x)$次数为$n-m$,$R(x)$次数小于$m$2. $F(x) ...
- 【Luogu4512】多项式除法(FFT)
题面 洛谷 题解 模板题... 我直接蒯我写的东西... 这个除法是带余除法,所以并不能直接求逆解决. 要求的就是给定两个多项式\(A(x),B(x)\),其项数为\(n,m\) 求解一个\(n-m\ ...
- 题解 P4512 【【模板】多项式除法】
题目地址 前言 原理有大佬写了 所以蒟蒻只讲下本题的代码细节 我看懂的大佬博客:博客地址 因为可能知道了大致的步骤还有很多细的地方不理解导致写的时候要花很久并且看到大佬们好像都是用递归写的希望能有帮助 ...
- Luogu4512 【模板】多项式除法(多项式求逆+NTT)
http://blog.miskcoo.com/2015/05/polynomial-division 好神啊! 通过翻转多项式消除余数的影响,主要原理是商只与次数不小于m的项有关. #include ...
随机推荐
- PSP个人软件开发工具需求分析文档
第一部分:前景与范围 1.业务需求 1.1 背景 在目前的软件项目开发过程中,进度计划总是非常不准确,经常出现延期,而且大多数都无法给出一个相对比较准确的延迟时间.即使使用用例包.用例的方式组织需求, ...
- presentViewController: 如何不覆盖原先的 viewController界面
PresentViewController 如何不遮挡住原来的viewController界面呢? 可能有时候会遇到这种需求,需要弹出一个功能比较独立的视图实现一些功能,但是却不想单纯添加一个View ...
- C#编写以管理员身份运行的程序
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; names ...
- 关于ajax解析
出处:http://www.cnblogs.com/huashanlin/archive/2006/10/09/524707.html 要很好地领会Ajax技术的关键是了解超文本传输协议(HTTP), ...
- 【转】Linux网络编程入门
(一)Linux网络编程--网络知识介绍 Linux网络编程--网络知识介绍客户端和服务端 网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户 ...
- (POJ 3694) Network 求桥个数
题目链接:http://poj.org/problem?id=3694Description A network administrator manages a large network. The ...
- 模板:Set类
头文件: #include <set> 定义: Set<string> set1; 添加: set1.insert("the"); 查询/获取元素 set1 ...
- Poj 3117 World Cup
1.Link: http://poj.org/problem?id=3117 2.Content: World Cup Time Limit: 1000MS Memory Limit: 65536 ...
- SQL 远程过程调用失败【0x800706be】或正在关闭 【0x80041033】解决方法
在SQL Server 配置管理器中出现[远程过程调用失败.[0x800706be]]或者[正在关闭 [0x80041033]]错误,如图所示 上网查找发现时SQL2008与VS2012或VS2013 ...
- 第一个C++
输入:cin>>(相当于scanf) #include <iostream> using namespace std; int main() { int number; ...