首页 > 其他分享 >PAT 甲级【1009 Product of Polynomials】

PAT 甲级【1009 Product of Polynomials】

时间:2023-10-23 20:44:36浏览次数:40  
标签:map Product PAT int double Polynomials nval new nextToken

/*
  1. 系数为0不输出
  2. 貌似runtime异常也显示答案不正确

    */




    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; public class Main { @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); in.nextToken(); int n = (int) in.nval; int[] N = new int[n]; double[] a = new double[n]; for (int i = 0; i < n; i++) { in.nextToken(); N[i] = (int) in.nval; in.nextToken(); a[i] = in.nval; } in.nextToken(); int m = (int) in.nval; int[] M = new int[m]; double[] b = new double[m]; for (int i = 0; i < m; i++) { in.nextToken(); M[i] = (int) in.nval; in.nextToken(); b[i] = in.nval; } double[] map = new double[N[0] + M[0]+1]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { map[N[i] + M[j]] += a[i] * b[j]; } } int k = 0; for (int i = N[0] + M[0]; i >= N[n - 1] + M[m - 1]; i--) { if (Math.abs(map[i]) > 0.0001) { k++; } } System.out.print(k); for (int i = N[0] + M[0]; i >= N[n - 1] + M[m - 1]; i--) { if (Math.abs(map[i]) > 0.0001) { System.out.print(String.format(" %d %.1f", i, map[i])); } } System.out.println(); } }

 

标签:map,Product,PAT,int,double,Polynomials,nval,new,nextToken
From: https://www.cnblogs.com/fishcanfly/p/17783421.html

相关文章

  • PAT 甲级1008【1008 Elevator】
    importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;importjava.io.StreamTokenizer;publicclassMain{@SuppressWarnings("unchecked")publicstaticvoidmain(String[]args)throwsIOException{......
  • xpath的contains用法
    xpath('//div[contains(@class,"a")andcontains(@class,"b")]')#它会取class含有有a和b的元素xpath('//div[contains(@class,"a")orcontains(@class,"b")]')#它会取class含有a或者b满足时,或者同时满足时的元素starts-with顾名思义,匹......
  • PAT 甲级【1007 Maximum Subsequence Sum】
    本题是考察动态规划与java的快速输入:max[i]表示第i个结尾的最大的连续子串和。bbegin[i]表示第[begin[i],i]为最大和的开始位置超时代码:importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;publicclassMain{@Suppres......
  • 一键解决WARNING: This is a development server. Do not use it in a production dep
    WARNING:Thisisadevelopmentserver.Donotuseitinaproductiondeployment.UseaproductionWSGIserverinstead.文章目录问题描述解决思路解决方法问题描述WARNING:Thisisadevelopmentserver.Donotuseitinaproductiondeployment.UseaproductionWS......
  • OSPF(Open Shortest Path First)vlink-peer
    配置流程1)系统视图下启用ipv6ipv62)创建ospfv3进程ospfv3100//进程为100router-id1.1.1.1//唯一标识为1.1.1.13)配置端口#interfaceGigabitEthernet0/0/1ipv6enable ipv6address2023:23::2/64 ipv6addressautolink-localospfv3100area0.0.0.1//将接口划分......
  • PAT_A1044 Shopping in Mars
    ShoppinginMarsisquiteadifferentexperience.TheMarspeoplepaybychaineddiamonds.Eachdiamondhasavalue(inMarsdollarsM$).Whenmakingthepayment,thechaincanbecutatanypositionforonlyonceandsomeofthediamondsaretakenoffth......
  • 多路径multipath共享磁盘配置
    1. 配置共享磁盘1.1. 主机关机的情况下,添加4块硬盘,每块磁盘设置如下  1.2. 另外一台主机添加上面已经存在的磁盘,同样设置 1.3. 修改两台虚拟机的配置文件(.vmx)disk.locking="FALSE"disk.EnableUUID="TRUE"scsi1:1.SharedBus="Virtual"......
  • 内核文档翻译(chatgpt) —— Pathname lookup (路径名查找)
    原文:https://www.kernel.org/doc/html/latest/filesystems/path-lookup.html内核中文件系统相关的文档汇总:FilesystemsintheLinuxkernelThiswrite-upisbasedonthreearticlespublishedatlwn.net:PathnamelookupinLinuxRCU-walk:fasterpathnamelookupinLi......
  • c: Visitor Pattern
     /***@filevalidator.h*@authoryourname([email protected])*@brief观察者模式VisitorPattern来源:C现代编程集成开发环境、设计模式、极限编程、测试驱动开发、重构、持续集成日.花井志生著,杨文轩译,人民邮电出版社*@version0.1*@date2023-10-21......
  • 动态加载目录进classpath
    参考文档:https://www.codelast.com/%E5%8E%9F%E5%88%9B-java%E5%8A%A8%E6%80%81%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E7%9B%AE%E5%BD%95%E5%88%B0classpath%E4%B8%AD/ publicstaticloadFoldertoClasspath(){FileprogramRootDir=newFile("./");URL......