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 ...
随机推荐
- CevaEclipse - 常用设置
1. 往工程里面添加在硬盘上已有的文件 File -> Import.. -> General -> File System From directory Browse... 勾选需 ...
- [ An Ac a Day ^_^ ] CodeForces 680A Bear and Five Cards
这两天回家了 家里电脑太卡 调试不方便 就只能写写水题了…… #include<stdio.h> #include<iostream> #include<algorith ...
- Vultr免费vps注册和使用简易教程
如果你是站长,寻找托管网站的主机,或者是开发者,需要搭建服务器环境,选购vps是必须的.强烈不推荐国内的vps产品,没有性价比,维护水平又烂,甚至某些国内所谓云主机vps安装后门,监控你的数据.海外v ...
- 去除VisualStudio中拼写错误检测的红色波浪线
去除VisualStudio中拼写错误检测的红色波浪线 在Visual Assistant中将 Underline spelling errors in comments and strings us ...
- C语言_cmd_pause
再C语言里面使用system函数调用pause. system("pause"); 会显示 请按任意键继续. . . system("pause ->nul&q ...
- javascript 如何正确使用getElementById,getElementsByName(), and getElementsByTagName()
WEB标准下可以通过getElementById(), getElementsByName(), and getElementsByTagName()访问DOCUMENT中的任一个标签. (1)get ...
- /etc/fstab 文件解释
/etc/fstab 文件解释 文件fstab包含了你的电脑上的存储设备及其文件系统的信息.它是决定一个硬盘(分区)被怎样使用或者说整合到整个系统中的唯一文件. 这个文件的全路径是/etc/fstab ...
- hdu 1394 Minimum Inversion Number(这道题改日我要用线段树再做一次哟~)
Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of ...
- hdu 1425 sort
Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行 ...
- window.open页面关闭后刷新父页面
如题 function openWin(url,text,winInfo){ var winObj = window.open(url,text,winInfo); var loop = setInt ...