A1009 Product of Polynomials (25)(25 分)
A1009 Product of Polynomials (25)(25 分)
This time, you are supposed to find A*B where A and B are two polynomials.
Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < ... < N2 < N1 <=1000.
Output Specification:
For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.
Sample Input
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output
3 3 3.6 2 6.0 1 1.6
思考
先考虑怎么存第一个样例
比起初试,还是机试爆零更可怕一点,所以确实是在大三下没有把握住机会啊,这学期有3门课,不应该那么烂的。
最高幂次数是2000,因为最大情况是1000*1000。
另外全局变量初始化不赋值,c语言默认处理为0啊,那么养成初始化赋值的习惯是极好的。
【c语言问题系列教程之一】变量声明和初始化 - CSDN博客 https://blog.csdn.net/mylinchi/article/details/52652595
C语言中全局变量初始化的重要性!!! - CSDN博客 https://blog.csdn.net/macrohasdefined/article/details/8814804
AC代码
#include<stdio.h>
struct Poly{
int exp;
double cof;
}poly[1001];//幂次数决定个数,正如数组下标是幂次数一样
double ans[2005]={0};//存放结果
int main(){
int n,m,number=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %lf",&poly[i].exp ,&poly[i].cof );
}//读入第一个多项式
scanf("%d",&m);
for(int i=0;i<m;i++){
int exp;
double cof;
scanf("%d %lf",&exp,&cof);//读入第二个多项式的一项
for(int j=0;j<n;j++){
ans[exp+poly[j].exp]+=(cof*poly[j].cof);//这个写法从A1042起步
}
}
for(int i=0;i<=2000;i++){//这里漏掉一个最高幂次数2000,就有两个测试点过不去
if(ans[i] !=0.0) number++;
}
printf("%d", number);
for(int i=2000;i>=0;i--){
if(ans[i] !=0.0){
printf(" %d %.1f",i ,ans[i]);//输出控制要注意
}
}
return 0;
}
A1009 Product of Polynomials (25)(25 分)的更多相关文章
- PAT A1009 Product of Polynomials (25 分)——浮点,结构体数组
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- 1009 Product of Polynomials (25 分)
1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two pol ...
- PAT A1009 Product of Polynomials(25)
课本AC代码 #include <cstdio> struct Poly { int exp;//指数 double cof; } poly[1001];//第一个多项式 double a ...
- A1009. Product of Polynomials
This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...
- PAT甲级——A1009 Product of Polynomials
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT 1009 Product of Polynomials
1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two p ...
- PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名
题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...
- PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)
1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...
- 1009 Product of Polynomials (25分) 多项式乘法
1009 Product of Polynomials (25分) This time, you are supposed to find A×B where A and B are two po ...
随机推荐
- Nginx支持PHP的CI框架
1.找到CI库的配置文件修改 $config['base_url'] = 'http://test.example.com'; $config['uri_protocol'] = 'PATH_I ...
- Windows安全认证是如何进行的?[Kerberos篇]
最近一段时间都在折腾安全(Security)方面的东西,比如Windows认证.非对称加密.数字证书.数字签名.TLS/SSL.WS-Security等.如果时间允许,我很乐意写一系列的文章与广大网友 ...
- MySQL中有关TIMESTAMP和DATETIME的对比
TIMESTAMP和DATETIME的相同点: 1> 两者都可用来表示YYYY-MM-DD HH:MM:SS[.fraction]类型的日期. TIMESTAMP和DATETIME的不同点: 1 ...
- 消息中间件之MQ详解及四大MQ比较
一.消息中间件相关知识 1.概述 消息队列已经逐渐成为企业IT系统内部通信的核心手段.它具有低耦合.可靠投递.广播.流量控制.最终一致性等一系列功能,成为异步RPC的主要手段之一.当今市面上有很多主流 ...
- 浅谈.htaccess文件--避免滥用.htaccess文件
.htaccess文件提供了一种目录级别的修改配置的方式. NOTE: 如果你拥有修改apache配置文件的权限,那么完全没有必要使用.htaccess文件.使用.htaccess文件会拖慢apach ...
- return false;和e.preventDefault;和e.stopPropagation的区别
因为有父, 子节点同在, 因为有监听事件和浏览器默认动作之分. 使用 JavaScript 时为了达到预期效果经常需要阻止事件和动作执行. 一般我们会用到三种方法, 分别是 stopPropagati ...
- ajax实现异步请求的过程
var xhr; xhr = new XMLHttpRequest(); //创建一个异步对象 xhr.open("Get", "test.a ...
- Python 加持,给你更有趣的 Azure 虚拟机开关重启方法!
在程序员的世界里,有关编程语言孰优孰劣的争论从来就没有消停过,不管你更粉哪种语言,毫无疑问,每种语言都有自己擅长的领域,而一些语言因为上手简单.扩展性强.功能强大等因素,往往会比较多地出现在我们面前, ...
- ASP.NET中登陆验证码的生成和输入验证码的验证
一:验证码的生成实现代码 protected void Page_Load(object sender, EventArgs e) { string validateCode = ...
- windows下php7.1.5、mysql环境搭建
php http://windows.php.net/download/ 如果是使用ISAPI的方式来运行PHP就必须用Thread Safe(线程安全)的版本:而用FastCGI模式运行PHP的话就 ...