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+ ...
随机推荐
- react基础(2)
react基础(1):介绍了如何创建项目,总结了JSX.组件.样式.事件.state.props.refs.map循环,另外还讲了mock数据和ajax 还是用 react基础1 里创建的项目继续写案 ...
- Raspiberry Camera详解+picamera库+Opencv控制
使用树莓派的摄像头,将树莓派自身提供的picamera的API数据转换为Python Oencv可用图像数据: # import the necessary packages from picamer ...
- QCW切割 --铁片
1.QCW切割旋转轴限位部件 --刘锦峰协助 :铁片 功率85% 最大功率100 最小功率50 脉宽0.1ms 调整焦点-0.5左右
- 怎样学好哲学(lucas+费马小定理)
怎样学习哲学 时间限制: 1 Sec 内存限制: 128 MB提交: 97 解决: 27[提交][状态][讨论版] 题目描述 OI大师抖儿在夺得银牌之后,顺利保送pku.这一天,抖儿问长者:&qu ...
- zoj 1526 Big Number 数学
Big Number Time Limit: 10 Seconds Memory Limit: 32768 KB In many applications very large intege ...
- webpack 的使用2
实际项目中的配置 要加__dirname 不然会报错 注意path /dist 前不要加点 结果 将两个文件打包在一起 结果 传入对象 并且单独打包 name为key 加上本次打包的hash has ...
- [Python]Codecombat攻略之远边的森林Forest(1-40关)
首页:https://cn.codecombat.com/play语言:Python 第二界面:远边的森林Forest(40关)时间:2-6小时内容:if/else.关系操作符.对象属性.处理输入网页 ...
- windowsxp_电脑桌面显示不出来。
问题:在工作的时候遇到电脑桌面显示不出来 解决方案: 1.结束explorer.exe进程 2.新建一个explorer.exe进程
- 干货|人人都是翻译项目的Master
在平时的工作中,我们都会经常查阅一些英文文档来解决平时遇到的问题和拓宽视野.看到好的文章或者书籍有没有想要和小伙伴分享的冲动,那么我们一起来翻译吧- 翻译主张 "信 达 雅" .& ...
- wpf GifBitmapDecoder 解析 gif 格式
在网上有很多图片都是gif,那么如何在 wpf 解析 gif? 本文告诉大家如何使用 GifBitmapDecoder 把gif分开为一张一张,获得他的信息. 如果需要把一个 gif 分开,使用的代码 ...