甲级1002 A+B for Polynomials (25)
题目描述:
This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file contains one test case. Each case occupies 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=, , ..., K) are the exponents and coefficients, respectively.
It is given that <= K <= , <= NK < ... < N2 < N1 <=. Output For each test case you should output the sum 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 to decimal place. Sample Input
2.4 3.2
1.5 0.5 Sample Output
1.5 2.9 3.2 @:
polynomial 多项式
exponents 指数
coefficients 系数
题目要求:
给出俩个多项式的指数和系数,没有给出基数,只要将指数相同的多项式进行系数相加即可。输出时按照指数从高到低的顺序输出。
注意题意,一开始没有看题意直接看的实例,忽略了负数情况相加之后系数可能为零从而不写,所以常用的单词还是得认得。。。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <math.h> using namespace std; int main()
{
int i,j,a,n;
int con=;
double s[],b;
int vis[];
memset(s,,sizeof(s));
memset(vis,,sizeof(vis)); for(i=;i<;i++)
{
scanf("%d", &n);
for(j=;j<n;j++)
{
scanf("%d %lf",&a,&b);
s[a]+=b;
}
} for(i=;i<=;i++)
if(s[i]!=)
con++; printf("%d", con); for(i=;i>=;i--)
if(s[i]!=)
printf(" %d %.1f",i,s[i]); printf("\n"); return ;
}
甲级1002 A+B for Polynomials (25)的更多相关文章
- PAT甲级 1002 A+B for Polynomials (25)(25 分)
1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...
- PAT 甲级1002 A+B for Polynomials (25)
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 1002 A+B for Polynomials (25)(25 point(s))
problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...
- 【PAT】1002. A+B for Polynomials (25)
1002. A+B for Polynomials (25) This time, you are supposed to find A+B where A and B are two polynom ...
- PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...
- PAT 甲级 1002 A+B for Polynomials (25 分)
1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polyno ...
- 【PAT甲级】1002 A+B for Polynomials (25 分)
题意:给出两个多项式,计算两个多项式的和,并以指数从大到小输出多项式的指数个数,指数和系数. AAAAAccepted code: #include<bits/stdc++.h> usin ...
随机推荐
- onload函数不执行
原因: <jsp:include page="">通过该标签引入jsp时会导致<body>失效 案例: <jsp:include page=" ...
- c++cmb
#include<windows.h> #include<bits/stdc++.h> using namespace std; ]; int main() { printf( ...
- hdu_2067_小兔的棋盘
小兔的叔叔从外面旅游回来给她带来了一个礼物,小兔高兴地跑回自己的房间,拆开一看是一个棋盘,小兔有所失望.不过没过几天发现了棋盘的好玩之处.从起点(0,0)走到终点(n,n)的最短路径数是C(2n,n) ...
- Sql Server 查看存储过程最后修改时间
Sql Server 查看存储过程最后修改时间 select * from sys.procedures order by modify_date desc
- lnmp配置支持thinkphp和nginx路由url重写
ThinkPHP3.2.3项目放到lnmp环境之后只能打开首页,或者通过传参方式打开控制器,否则就一直显示404页面.搞了一上午,终于解决了 step1: 修改php.ini cgi.fix_path ...
- phpstudy apache启动失败,80端口占用问题解决方案
安装phpstydy,启动apache时,启动失败,提示80端口占用,需要将占用80端口的服务进程关闭 1.运行cmd, netstat -ano 找到80端口对应的pid 4 2.一般都是调用 h ...
- 【php】php 生僻知识点认知
资料引用来源:http://www.runoob.com/php/php-tutorial.html 表单提交中, 变量名中的点和空格被转换成下划线.例如 <input name=" ...
- Hadoop(23)-Yarn资源调度器
Yarn是一个资源调度平台,负责为运算程序提供服务器运算资源,相当于一个分布式的操作系统平台,而MapReduce等运算程序则相当于运行于操作系统之上的应用程序 1. Yarn工作机制 机制详解 第1 ...
- spark-day1
#!/usr/bin/python # -*- coding: utf_8 -*- from pyspark import SparkConf, SparkContext import os, tim ...
- 675. Cut Off Trees for Golf Event
// Potential improvements: // 1. we can use vector<int> { h, x, y } to replace Element, sortin ...