zoukankan      html  css  js  c++  java
  • 1002. A+B for Polynomials

    C++语言: Codee#25843
    01 /*
    02 +++++++++++++++++++++++++++++++++++++++
    03                 author: chm
    04 +++++++++++++++++++++++++++++++++++++++
    05 */
    06
    07 #include <map>
    08 #include <set>
    09 #include <list>
    10 #include <queue>
    11 #include <cmath>
    12 #include <stack>
    13 #include <bitset>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <string>
    17 #include <vector>
    18 #include <cassert>
    19 #include <cstdlib>
    20 #include <cstring>
    21 #include <fstream>
    22 #include <sstream>
    23 #include <iomanip>
    24 #include <iostream>
    25 #include <algorithm>
    26
    27 using namespace std;
    28
    29 FILE*            fin         = stdin;
    30 FILE*            fout         = stdout;
    31 const int        max_size     = 10086;
    32
    33 float buf[max_size];
    34 #define ONLINE_JUDGE
    35 int main()
    36 {
    37 #ifndef ONLINE_JUDGE
    38     freopen("d:\\in.txt", "r", stdin);
    39     freopen("d:\\out.txt", "w", stdout);
    40 #endif
    41     /*
    42        数据小 直接数组通过
    43        */
    44     int n, m;
    45     int a;
    46     float b;
    47     while(scanf("%d", &n) != EOF)
    48     {
    49         memset(buf, 0, sizeof(buf));
    50         for(int i = 0; i < n; ++i)                          //read,add
    51         {
    52             scanf("%d%f", &a, &b);
    53             buf[a] += b;
    54         }
    55         scanf("%d", &m);
    56         int nonzero = 0;
    57         for(int i = 0; i < m; ++i)                            //read ,add
    58         {
    59             scanf("%d%f", &a, &b);
    60             buf[a] += b;
    61         }
    62         for(int i = 0; i <= 1000; ++i)
    63             if(fabs(buf[i]) > 1e-6)
    64                 ++nonzero;
    65         printf("%d%s", nonzero, nonzero ? " " : "\n");
    66         for(int i = 1000, cnt = 0; i >= 0; --i)          //print,form large to small
    67             if(fabs(buf[i]) > 1e-6)
    68                 printf("%d %.1f%s", i, buf[i], ++cnt == nonzero ? "\n" : " ");
    69     }
    70
    71 #ifndef ONLINE_JUDGE
    72     fclose(stdout);
    73     system("start d:\\check.exe d:\\out.txt d:\\ans.txt");
    74 #endif
    75     return 0;
    76 }
  • 相关阅读:
    extgcd 扩展欧几里得算法模板
    51nod 1073约瑟夫环
    UVA 11806 Cheerleaders (容斥原理
    HDU 1863 畅通工程 (最小生成树
    并查集模板
    51NOD 1072 威佐夫游戏
    Java基于JAX-RD开发Restful接口
    tomcat的webapps下放置多个项目时会出现很多exception
    带滚动条的表格
    禁止apache显示目录索引的常见方法
  • 原文地址:https://www.cnblogs.com/invisible/p/2400433.html
Copyright © 2011-2022 走看看