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

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

  代码如下:

#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. Java I/O 操作的一些基本知识

    1.文件类:File ,也是唯一的单独的文件类.可以对文件进行操作.其方法有:exists(),delete(),isDirectory(),createNewFile(),getName(),get ...

  2. mongodb安装 win7版

    首先下载mongdb的zip包,可以到:http://www.mongodb.org/downloads.选择32位或64位的. 在D盘创建mongodb文件夹,d:\mongodb.把解压里面所有的 ...

  3. TFS 2012使用简介

    为什么使用TFS 2012进行源代码管理——TFS 2012使用简介(一)  来源:雪雁 http://www.cnblogs.com/codelove/archive/2013/03/16/2963 ...

  4. 第1章 初识java----输出多行的语句写法

    public class onesixtwo{ public static void main(String[] args){ System.out.println("----------- ...

  5. localStorage请使用getItem 和setITem

    最近看别人的代码,发现他们在从localStorage里面的时候喜欢用dot来操作,而不是get setItem,记得以前说过这个事.下面再说一次吧. 用dot方式来操作(   每次以'hello'= ...

  6. .net解决js访问服务器端,跨域访问的问题

    在Global.asax.cs文件中,添加 protected void Application_BeginRequest(object sender, EventArgs e) { HttpCont ...

  7. 虚拟机 centos 7 nginx安装

    1下载vmware 12,并安装.百度即可 2下载centos 7,将其安装在vmware 12中.百度即可,无复杂设置. 3设置vmware 中centos7能上网: a.右键计算机->管理- ...

  8. android Bind机制(二)

    1.binder通信概述 binder通信是一种client-server的通信结构,    1.从表面上来看,是client通过获得一个server的代理接口,对server进行直接调用:    2 ...

  9. iOS特殊字符的转义字符

    所有的ASCII码都可以用“\”加数字(一般是8进制数字)来表示.而C中定义了一些字母前加"\"来表示常见的那些不能显示的ASCII字符,如\0,\t,\n等,就称为转义字符,因为 ...

  10. Apriori算法-数组-C语言

    原文地址:http://blog.csdn.net/liema2000/article/details/6118423 #include<stdio.h>typedef struct { ...