NBUT The Sum of F(x) and G(x)

  • 问题描述
  • When Deathmoon played MC game, he faced a math problem. When he found a ancient tomb and came in, he found two polynomials f(x) and g(x) no the wall, only did he calculate f(x) + g(x) correctly he could come in, can you help him?

    For example:

    f(x) = 2*x^5 + 3*x^3 + 7 + x^(-1),

    g(x) = 3*x^4 + 2*x^3 + x - x^(-1).

    Then,

    f(x) + g(x) = 2*x^5 + 3*x^4 + 5*x^3 + x + 7

  • 输入
  • Input end of EOF.

    First I will give you two positive integers N and M(0 < N, M < 10) means the number of items in polynomials.

    Then N lines follow, each line contains two integers c(-100 < c < 100) and p(-10 <= p <= 10), c means the coefficients and p means the power.

    Then M lines follow, each line contains two integers c(-100 < c < 100) and p(-10 <= p <= 10), c means the coefficients and p means the power.

    And for each test, every polynomial‘ s power is descending, it means pi > pj when i < j.

    c != 0 && p != 0.

  • 输出
  • You should output (f(x) + g(x))‘ s expression for coefficients and powers in descending.
  • 样例输入
  • 4 4
    2 5
    3 3
    7 0
    1 -1
    3 4
    2 3
    1 1
    -1 -1
    
  • 样例输出
  • 2 5
    3 4
    5 3
    1 1
    7 0
    
  • 提示
  • f(x) = coefficients * x ^ power;
    The sample input:
    f(x) = 2*x^5 + 3*x^3 + 7 + x^(-1),
    g(x) = 3*x^4 + 2*x^3 + x - x^(-1).
    The sample output:
    f(x) + g(x) = 2*x^5 + 3*x^4 + 5*x^3 + x + 7
    

题意:显而易见

思路:纯模拟,让下标确定为正数就是了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 1000;

int n,m;
int arr[MAXN];
int vis[MAXN];

int main(){
	while (scanf("%d%d", &n, &m) != EOF){
		int c,p;
		memset(vis,0,sizeof(vis));
		for (int i = 0; i < n; i++){
			scanf("%d%d", &c, &p);
			arr[p+10] = c;
			vis[p+10] = 1;  //确保正数
		}
		for (int i = 0; i < m; i++){
			scanf("%d%d", &c, &p);
			if (vis[p+10]){
				arr[p+10] += c;
				if (arr[p+10] == 0)
					vis[p+10] = 0;
			}
			else {
				vis[p+10] = 1;
				arr[p+10] = c;
			}
		}
		for (int i = 20; i >= 0; i--)
			if (vis[i])
				printf("%d %d\n", arr[i], i-10);
	}
	return 0;
}

NBUT The Sum of F(x) and G(x)

时间: 2024-08-03 10:54:27

NBUT The Sum of F(x) and G(x)的相关文章

###柯里化 f(x,y) -&gt; g(x)(y)

python 柯里化 f(x,y) -> g(x)(y) def bigger(x): def inner_bigger(y): return y>x return inner_bigger list(filter(bigger(5),range(10))) #filter返回一个迭代器,用list接收 [6, 7, 8, 9] list(filter(bigger(3),range(10))) [4, 5, 6, 7, 8, 9]实例化一下:bigger_3 = bigger(3)bigge

hunnu Sum of f(x)

http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11546&courseid=0 Sum of f(x) Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB Total submit users: 196, Accepted users: 118 Problem 11546 : No special judgement Prob

2017Summmer_上海金马五校 F题,G题,I题,K题

以下题目均自己搜 F题  A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R,然后对整个数组扫一遍对于每一个下标取m=min(L[i],R[i]);用ans取2*m-1中的最大值.LIS用nlogn的算法实现,二分用的是lower_bound(),直接看代码. //Author: xiaowuga #include <bits/stdc++.h> #define maxx

hunnu11546:Sum of f(x)

Problem description   令f(x)为x的所有约数之和,x的约数即可以被x整除的数,如f(24)=1+2+3+4+6+8+12+24=60),求 f(l) + f(l + 1) + -- + f(r) Input   第一行为一个整数T(T<=100000),表示数据的组数. 接下来T行,每行有两个整数l,r(1 <= l <= r <= 200000) Output   对每组数据,输出f(l)+f(l+1)+--+f(r) 的和 Sample Input 2

hnnu 11546 Sum of f(x) (求一个数的所有约数和)

代码: #include<cstdio> #include<cstring> #define N 200000 using namespace std; long long f[N+5]; long long s[N+5]; int main() { s[0]=0; for(int i=1;i<=N;i++) { for(int j=1;j*i<=N;j++) { f[j*i]+=i; } } for(int i=1;i<=N;i++) { s[i]=s[i-1]

codevs1085数字游戏(环形DP+划分DP )

1085 数字游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易.游戏是这样的,在你面前有一圈整数(一共n个),你要按顺序将其分为m个部分,各部分内的数字相加,相加所得的m个结果对10取模后再相乘,最终得到一个数k.游戏的要求是使你所得的k最大或者最小. 例如,对于下面这圈数字(n=4,m=2): 2

BZOJ2724: [Violet 6]蒲公英

2724: [Violet 6]蒲公英 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 795  Solved: 248[Submit][Status] Description Input 修正一下 l = (l_0 + x - 1) mod n + 1, r = (r_0 + x - 1) mod n + 1 Output Sample Input Sample Output HINT 修正下: n <= 40000, m <= 50000 S

【bzoj2213】[Poi2011]Difference dp

题目描述 已知一个长度为n的由小写字母组成的字符串,求其中连续的一段,满足该段中出现最多的字母出现的个数减去该段中出现最少的字母出现的个数最大.求这个个数. 输入 第一行,n第二行,该字符串1<=n<=1000000 输出 一行,表示结果 样例输入 10 aabbaaabab 样例输出 3 题解 dp 令$sum[i][j]$表示前$i$个字母中$j$的出现次数,那么题目所求的是$Max((sum[r][i]-sum[l-1][i])-(sum[r][j]-sum[l-1][j]))=Max(

codevs 2102 石子归并2

传送门 2102 石子归并 2 时间限制: 10 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分.试设计出1个算法,计算出将N堆石子合并成1堆的最小得分和最大得分. 输入描述 Input Description 数据的第1行试正整数N,1≤N≤100,表示有N堆石子.第2行有N个数,分别表示每堆石子的