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 ...
随机推荐
- kindeditor编辑器,图片上传功能齐全
废话不多说直接上文件包压缩包:kindeditor图片上传(VS2012)
- Openjudge-计算概论(A)-与7无关的数
描述: 一个正整数,如果它能被7整除,或者它的十进制表示法中某一位上的数字为7,则称其为与7相关的数.现求所有小于等于n(n < 100)的与7无关的正整数的平方和. 输入输入为一行,正整数n( ...
- ural 1119. Metro(动态规划)
1119. Metro Time limit: 0.5 second Memory limit: 64 MB Many of SKB Kontur programmers like to get to ...
- 如何用Navicat for MySQL 将mysql中的数据库导出,导入。
数据库导出 1.双击要导出的数据库,右键选转储SQL文件...,选择要保存的文件夹. 2.点击开始后,开始导出. 数据库导入 1.新建数据库,数据库的名字必须和导入的数据库文件一致. 2.在新建的数据 ...
- linux zeromq
本人在centos下安装zeromq 1.下载最新版的zeromq http://download.zeromq.org/ 2 解压 tar -xvf zeromq-3.1.0-beta.tar.gz ...
- ios UIApplocation 中APP启动方式
iOS app启动的方式有哪些: 自己启动(用户手动点击启动) urlscheme启动(关于urlScheme的详解)http://www.cnblogs.com/sunfuyou/p/6183064 ...
- 简单的setInterval应用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- c语言-转义序列
字符组合是由反斜杠 (\) 后接字母或位组合构成的字符组合.若要显示换行符,单引号或某些其他字符在字符串末尾,必须使用转义序列. 转义序列被视为单个字符,因此,它是有效的字符常数. 转义序列通常用于指 ...
- 自定义VBS脚本(统计在指定文件中搜索字符串出现的次数)
'=========================================================================='' VBScript Source File - ...
- shell脚本学习(二)
4.cat命令 1) cat -s 摆脱多余的空白行 2) cat -T 将制表符显示为^I 3) cat -n 显示行号 4) cat -b 跳过空白行,然后显示行号 ...