UVALive 2323 Modular Multiplication of Polynomials(模拟)
这是一个相对简单的模拟,因为运算规则已经告诉了我们,并且比较简单,不要被吓到……
思路:多项式除以另外一个多项式,如果能除,那么他的最高次一定被降低了,如果最高次不能被降低,那说明已经无法被除,就是题目要求输出的膜了,降低最高次的方法很简单,只要被除式的最高次 >= 除式的最高次,就将除式的最高次升高到与被除式一样高,然后让被除式减去它,直到不满足上述关系为止。
代码如下:
#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(模拟)的更多相关文章
- POJ1060 Modular multiplication of polynomials
题目来源:http://poj.org/problem?id=1060 题目大意: 考虑系数为0和1的多项式.两个多项式的加法可以通过把相应次数项的系数相加而实现.但此处我们用模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 ...
- POJ 1060:Modular multiplication of polynomials
Modular multiplication of polynomials Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4 ...
- POJ 1060 Modular multiplication of polynomials(多项式的加减乘除,除法转化成减法来求)
题意:给出f(x),g(x),h(x)的 (最高次幂+1)的值,以及它们的各项系数,求f(x)*g(x)/h(x)的余数. 这里多项式的系数只有1或0,因为题目要求:这里多项式的加减法是将系数相加/减 ...
- 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 ...
- PAT 1009 Product of Polynomials 模拟
This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...
- UVALive 5880 Vigenère Cipher Encryption (模拟)
Stack Machine Executor 题目链接: http://acm.hust.edu.cn/vjudge/problem/26628 Description http://7xjob4.c ...
- UVa 442 Matrix Chain Multiplication(矩阵链,模拟栈)
意甲冠军 由于矩阵乘法计算链表达的数量,需要的计算 后的电流等于行的矩阵的矩阵的列数 他们乘足够的人才 非法输出error 输入是严格合法的 即使仅仅有两个相乘也会用括号括起来 并且括号中 ...
- UVALive 4222 /HDU 2961 Dance 大模拟
Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...
随机推荐
- python 列表、字典的方法
# 列表最后新增元素 li = [11, 22, 33] print(li) li.append(44) # 对原列表最后增加一个元素 print(li) 执行如下: [11, 22, 33][11, ...
- java innerclass
---恢复内容开始--- 内部类: public class Inner{ public class Inner2{} } 创建内部类对象 .new public class Test { in ...
- java集合概念
Collection(单列集合) List(有序,可重复) ArrayList 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector 底层数据结构是数组,查询快,增删慢 线程安全,效率 ...
- Linux Debian 7部署LEMP(Linux+Nginx+MySQL+PHP)网站环境
我们在玩VPS搭建网站环境的时候,都经常看到所谓的LAMP.LNMP.LEMP,LAMP, 其中的A代表APECHE WEB驱动环境,LNMP中的N代表NGINX驱动环境,只不过海外的叫法NGINX ...
- ios xcode中所有自带的字体如下(最好结合NSMutableAttributedString相结合使用)
// 打印系统中所有字体的类型名字 NSArray *familyNames = [UIFont familyNames]; for(NSString *familyName in familyNam ...
- mongodb 数据库导入.cvs文件时某些字段类型变成NumberLong的解决办法
在mongodb中导入数据时,会在数据库中生成字段记录为NumberLong的数据,可以使用以下方式将其转换为String db.Account.find().forEach( function(it ...
- VB.net结束进程
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...
- 用VS2012或VS2013在win7下编写的程序在XP下运行就出现“不是有效的win32应用程序
经常创建项目的时候,采用空项目,那么编译成功后,最好修改下sbusystem . 链接器->系统->子系统->控制台或windows 后面的"最低版本"是5.01
- git 常用使用及问题记录
1.打开bash,进入工程根目录(引用whaon的话:是和.classpath和.project同级的目录).PS:我的系统是win7,在bash切换到E的命令是 cd /e: 2.运行 git in ...
- j2ee网站项目首页如何直接使用action
之前做过一些网站项目,大多数都是首页就是登录,直接进入首页的不多,也就没有注意到,今天刚好注意到了就来记一下.也算是一个小技巧 <welcome-file>index.jsp</we ...