PAT-甲级-1002
1、来,先看题,https://www.patest.cn/contests/pat-a-practise/1002。
2、需要注意的地方只有一个:两个多项式相加之后,系数可能为零,这些项不应该出现在输出中,也不应该算在总的项数内。
接下来,就是一顿无脑暴力了:
#include<iostream>
#include<iomanip>
using namespace std;
typedef struct {
int expo;
double coef;
} node;
int ka,kb;
node a[],b[];
int exist(node n) {
for(int i=; i<ka; i++) if(a[i].expo==n.expo) return i;
return -;
}
int main(void) {
cin>>ka;
for(int i=; i<ka; i++) cin>>a[i].expo>>a[i].coef;
cin>>kb;
for(int i=; i<kb; i++) cin>>b[i].expo>>b[i].coef;
int len=ka;
for(int i=; i<kb; i++) {
if(exist(b[i])!=-) a[exist(b[i])].coef+=b[i].coef;
else {
a[len].expo=b[i].expo;
a[len++].coef+=b[i].coef;
}
}
for(int i=; i<len; i++) {
for(int j=i+; j<len; j++) {
if(a[j].expo>a[i].expo) {
double c=a[i].coef;
int e=a[i].expo;
a[i].coef=a[j].coef;
a[i].expo=a[j].expo;
a[j].coef=c;
a[j].expo=e;
}
}
}
int count=;
for(int i=; i<len; i++) {
if(a[i].coef) count++;
}
cout<<count;
for(int i=; i<len; i++)
if(a[i].coef!=)
printf(" %d %.1lf",a[i].expo,a[i].coef);
cout<<endl;
}
其实,只要做好“零系数”这个特殊情况的处理,就不会报错了。
PAT-甲级-1002的更多相关文章
- 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
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805526272000000 This time, you are sup ...
- PAT甲级1002水题飘过
#include<iostream> #include<string.h> using namespace std; ]; int main(){ int n1, n2; wh ...
- PAT甲级——1002 A+B for Polynomials
PATA1002 A+B for Polynomials This time, you are supposed to find A+B where A and B are two polynomia ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级1107. Social Clusters
PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...
- PAT甲级代码仓库
大道至简,知易行难.希望能够坚持刷题. PAT甲级真题题库,附上我的代码. Label Title Score Code Level 1001 A+B Format 20 1001 * 1002 A+ ...
随机推荐
- Python uwsgi 无法安装以及编译报错的处理方式
之前安装uwsgi的时候编译一步有出错,因为比较早,部分错误代码已经找不到了,网上找了部分错误信息, 现把解决方式共享出来. 环境:CentOS release 6.4 Python 2.7.3 ...
- 非常有用的css使用总结
积小流以成江海,很多东西你不总结就不是你的东西 常用css总结: /*设置字体*/ @font-face { font-family: 'myFont'; src: url('../font/myFo ...
- ADALINE模型
ADALINE模型即自适应线性单元(Adaptive Linear Neuron),主要用于信号处理中的自适应滤波.预测和模式识别.其结构图如下 输入向量X=(x0,x1,x2,...,xn)T每个输 ...
- STM8学习
今天正式学习STM8,用的是风驰STM8S208R开发板. 在编译例程遇到了如下这样的问题. " #error clnk debug\stm8s_demo.lkf:47 can't open ...
- python中strip函数的用法
python中往往使用剥除函数strip()来对用户的输入进行清理.strip函数的最一般形式为: str.strip('序列') 其中,序列是一段字符串,该函数表示从头或者从尾部开始进行扫描,如果扫 ...
- 小程序的get和post请求头的区别
小程序在使用wx.request()接口 时 header 请求头默认是这样的 wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' ...
- zoj3953 Intervals 最大不重叠区间加强版 zoj排名第一~
Intervals Time Limit: 1 Second Memory Limit:65536 KB Special Judge Chiaki has n intervals ...
- Winform窗体间传递数据
public string passText { get { return textBox1.Text; } } //Form1中还有个按钮button1在其点击事件中有: private void ...
- 基于Redis位图实现系统用户登录统计
项目需求,试着写了一个简单登录统计,基本功能都实现了,日志数据量小.具体性能没有进行测试~ 记录下开发过程与代码,留着以后改进! 1. 需求 1. 实现记录用户哪天进行了登录,每天只记录是否登录过,重 ...
- GooglePlay - 文件上传限制的扩展
前言 Google Play应用商店在上传限制100MB大小,超过该大小的应用必须将超过部分以扩展文件的形式进行上传处理. 总共可上传2个扩展文件,每个最大文件可为2GB,同时obb文件格式可自选. ...