这是一个相对简单的模拟,因为运算规则已经告诉了我们,并且比较简单,不要被吓到……

  思路:多项式除以另外一个多项式,如果能除,那么他的最高次一定被降低了,如果最高次不能被降低,那说明已经无法被除,就是题目要求输出的膜了,降低最高次的方法很简单,只要被除式的最高次 >= 除式的最高次,就将除式的最高次升高到与被除式一样高,然后让被除式减去它,直到不满足上述关系为止。

  代码如下:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define maxn 1100
int f[maxn],g[maxn],h[maxn];
int mul[maxn*],now[maxn*];
int main()
{
int t,f1,g1,h1,m1,tmp;
scanf("%d",&t);
while(t--){
scanf("%d",&f1);
for(int i = f1-;i >= ;i--) scanf("%d",&f[i]);
scanf("%d",&g1);
for(int i = g1-;i >= ;i--) scanf("%d",&g[i]);
scanf("%d",&h1);
for(int i = h1-;i >= ;i--) scanf("%d",&h[i]);
for(int i = ;i <= f1+g1;i++) mul[i] = ;
for(int i = ;i < f1;i++){
for(int j = ;j < g1;j++){
mul[i+j] += f[i]*g[j];
mul[i+j] %= ;
}
}
h1--;
m1 = f1+g1-;
while(h1 <= m1){
tmp = m1 - h1;
for(int i = ;i <= m1;i++) now[i] = ;
for(int i = ;i <= h1;i++){
now[i+tmp] = h[i];
}
for(int i = m1;i >= ;i--) mul[i] = (mul[i]+now[i])%;
for(int i = m1;i >= ;i--) {
if(mul[i]){
m1 = i;
break;
}
}
}
printf("%d",m1+);
for(int i = m1;i >= ;i--){
printf(" %d",mul[i]);
}
puts("");
}
return ;
}

UVALive 2323 Modular Multiplication of Polynomials(模拟)的更多相关文章

  1. POJ1060 Modular multiplication of polynomials

    题目来源:http://poj.org/problem?id=1060 题目大意: 考虑系数为0和1的多项式.两个多项式的加法可以通过把相应次数项的系数相加而实现.但此处我们用模2加法来计算系数之和. ...

  2. POJ1060 Modular multiplication of polynomials解题报告 (2011-12-09 20:27:53)

    Modular multiplication of polynomials Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3 ...

  3. POJ 1060:Modular multiplication of polynomials

    Modular multiplication of polynomials Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4 ...

  4. POJ 1060 Modular multiplication of polynomials(多项式的加减乘除,除法转化成减法来求)

    题意:给出f(x),g(x),h(x)的 (最高次幂+1)的值,以及它们的各项系数,求f(x)*g(x)/h(x)的余数. 这里多项式的系数只有1或0,因为题目要求:这里多项式的加减法是将系数相加/减 ...

  5. Lintcode: Hash Function && Summary: Modular Multiplication, Addition, Power && Summary: 长整形long

    In data structure Hash, hash function is used to convert a string(or any other type) into an integer ...

  6. PAT 1009 Product of Polynomials 模拟

    This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...

  7. UVALive 5880 Vigenère Cipher Encryption (模拟)

    Stack Machine Executor 题目链接: http://acm.hust.edu.cn/vjudge/problem/26628 Description http://7xjob4.c ...

  8. UVa 442 Matrix Chain Multiplication(矩阵链,模拟栈)

    意甲冠军  由于矩阵乘法计算链表达的数量,需要的计算  后的电流等于行的矩阵的矩阵的列数  他们乘足够的人才  非法输出error 输入是严格合法的  即使仅仅有两个相乘也会用括号括起来  并且括号中 ...

  9. UVALive 4222 /HDU 2961 Dance 大模拟

    Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...

随机推荐

  1. Python 学习笔记6

    做人要有目标感! 继续学习Python哦.

  2. ASP.NET中的Excel操作(NPOI方式)

    代码准备: 一:实体准备 代码如下: /// <summary> /// 一个能添加到将要导出到指定行的实体类型规范 /// data:{int StartColIndex ? 0, in ...

  3. grub引导centos

    下面来主要讲一下在grub下来引导centos: 其步骤如下; a   进入grub的命令模式. b  先熟悉一下grub  的一些命令 grub>help c  熟悉一下cat命令 d  ro ...

  4. 对方网络ping不通

    后台接口往往部署在其他服务器上如果ping不同 很大可能是因为对方开防火墙的原因 解决方法:控制面板-windows防火墙-打开或关闭windows防火墙

  5. html5 画个圈

    <html><body><canvas id="myCanvas" width="200" height="100&qu ...

  6. mvc的IIS 配置问题 runAllManagedModulesForAllRequests 与 HtmlFileHandler

    runAllManagedModulesForAllRequests 一般设置为false,当为true时所有的资源将进入mvc处理,无疑会给服务器加大压力. 解决办法是时使用HtmlFileHand ...

  7. java并发编程框架 Executor ExecutorService invokeall

    首先介绍两个重要的接口,Executor和ExecutorService,定义如下: public interface Executor { void execute(Runnable command ...

  8. C#中泛型默认关键字(default)详解

    我们在泛型类和泛型方法中产生的一个问题是,在预先未知以下情况时,如何将默认值分配给参数化类型 T:(T 是引用类型还是值类型?)对此我们将如何处理? C#代码实例: /// <summary&g ...

  9. Apriori算法-位运算-C语言

    原文地址:http://blog.csdn.net/liema2000/article/details/6118423 //////////////////////////////////////// ...

  10. php 项目简单分类

    项目分为:客户需求和自行研发. 商城项目:------------------------商城分类:单商家:商家就是网站所有者.如京东.凡客.          多商家:如淘宝 网站所有者不是卖家.  ...