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 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 1 decimal place.

Sample Input:

  1. 2 1 2.4 0 3.2
  2. 2 2 1.5 1 0.5
 

Sample Output:

  1. 3 2 1.5 1 2.9 0 3.2
 
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
 

解题:

  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main()
  5. {
  6. int k,i,j,l,c=0;
  7. int temp[1001];
  8. int flag=1;
  9. float arr1[1001],arr2[1001],temparr[1001];
  10. memset(arr1,0,sizeof(arr1));
  11. memset(arr2,0,sizeof(arr2));
  12. memset(temparr,0,sizeof(temparr));
  13. memset(temp,1001,sizeof(temp));
  14. scanf("%d ",&k);
  15. for(i=0;i<k;i++)
  16. {
  17. scanf("%d ",&j);
  18. for(l=0;l<k;l++){
  19. if(temp[l]==j)
  20. {
  21. scanf("%f ",&temparr[j]);
  22. arr1[j]+=temparr[j];
  23. flag=0;
  24. }
  25. }
  26. if(flag==1)
  27. {
  28. temp[i]=j;
  29. scanf("%f ",&arr1[j]);
  30. }
  31. flag=1;
  32. }
  33. //printf("%d %d %.1f",k,j,arr1[1]);
  34. scanf("%d ", &k);
  35. for(i=0;i<k;i++)
  36. {
  37. scanf("%d ",&j);
  38. for(l=0;l<k;l++){
  39. if(temp[l]==j)
  40. {
  41. scanf("%f ",&temparr[j]);
  42. arr2[j]+=temparr[j];
  43. flag=0;
  44. }
  45. }
  46. if(flag==1)
  47. {
  48. temp[i]=j;
  49. scanf("%f ",&arr2[j]);
  50. }
  51. flag=1;
  52. }
  53.  
  54. for(i=0;i<12;i++)
  55. {
  56. arr1[i]=arr1[i]+arr2[i];
  57. }
  58. for(i=0;i<12;i++)
  59. {
  60. if(arr1[i]!=0)
  61. {
  62. c++;
  63. }
  64. }
  65. printf("%d",c);
  66. for(i=12;i>=0;i--)
  67. {
  68. if(arr1[i]!=0)
  69. {
  70. printf(" %d %.1f",i,arr1[i]);
  71. }
  72. }
  73. }
 

PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25的更多相关文章

  1. 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 ...

  2. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...

  3. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) (排序)

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  4. PAT (Basic Level) Practice 1002 写出这个数 分数 20

    读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 10100. 输出格式: 在一行内输出 ...

  5. PAT (Basic Level) Practice 1005 继续(3n+1)猜想 分数 25

    卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对 n=3 进行验证的时 ...

  6. PAT (Advanced Level) Practice 1001-1005

    PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...

  7. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

  8. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  9. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

随机推荐

  1. qbxt数学五一Day4

    目录 1. 随机试验 2. 概率 1. 平凡 2. 条件概率 3. 期望 习题 1 2 3 4 1. 随机试验 定义: 不能预先确知结果 试验之前可以预测所有可能结果或范围 可以在相同条件下重复实验 ...

  2. 从零开始Blazor Server(6)--基于策略的权限验证

    写这个的原因 现在BootstrapBlazor处于大更新时期,Menu组件要改为泛型模式. 本来我们的这一篇应该是把Layout改了,但是改Layout肯定要涉及到菜单,如果现在写了呢,就进入一个发 ...

  3. CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-E

    比赛链接 A 题解 知识点:思维,模拟. 发现 \(b\) 串第一个字符是 \(1\) 则只能使用 max , \(0\) 则只能使用 min ,随后只需要模拟到 \(a\) 串剩余 \(m\) 个字 ...

  4. Python基础之字符串和编码

    字符串和编码 字符串也是一种数据类型,但是字符串比较特殊的是还有个编码问题. 因为计算机自能处理数字,如果徐娅处理文本,就必须先把文本转换为数字才能处理,最早的计算机子设计时候采用8个比特(bit)作 ...

  5. jQuery基础入门(一)

    jQuery是什么? jQuery是一个JavaScript常用的工具函数库.jQuery是一个轻量级的"写的少,做的多"的JavaScript库. jQuery当中包含有以下一些 ...

  6. CF383C Propagating tree (线段树,欧拉序)

    \(tag\)没开够\(WA\)了一发... 求出\(dfs\)序,然后按深度分类更新与查询. #include <iostream> #include <cstdio> #i ...

  7. ABP vNext系列文章03---依赖注入

    一.依赖注入的类型注册 ABP的依赖注入系统是基于Microsoft的依赖注入扩展库(Microsoft.Extensions.DependencyInjection nuget包)开发的.因此,它的 ...

  8. Excel 插入嵌入式图表和独立图表的方法

    描述 嵌入式图表:是一种与当前工作表相同位置的图表,且悬浮在表格之上,不受表格限制,因此称之为嵌入式图表. 独立图表:是独立于当前工作表的图表,打印时,需要单独将其打印出来. 插入独立图表的图文教程: ...

  9. 从零开始Blazor Server(15)--总结

    我们用了14篇文章,基本上把一个后台管理系统需要的UI部分都说的差不多了.所以这套文章也该到了结束的时候了. 这里面有很多问题,比如我们直接使用UI来拉数据库信息而没有使用service,再比如我们大 ...

  10. 牛客CSP-S模拟题——十二桥问题

    题面 n <= 50000,m <= 200000,k <= 12 题解 可以从K条边的两端和1结点出发各进行一次O(nlogn)的Dijk,然后就浓缩成了一个最多只有25个点的小完 ...