ZOJ 2969 模拟 (E)
2015-11-07 23:23
369 查看
Easy Task
Time Limit: 2 Seconds Memory Limit: 65536 KB
Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))' to denote its derivation. We use x^n to denote xn. To calculate the derivation
of a polynomial, you should know 3 rules:
(1) (C)'=0 where C is a constant.
(2) (Cx^n)'=C*n*x^(n-1) where n>=1 and C is a constant.
(3) (f1(x)+f2(x))'=(f1(x))'+(f2(x))'.
It is easy to prove that the derivation a polynomial is also a polynomial.
Here comes the problem, given a polynomial f(x) with non-negative coefficients, can you write a program to calculate the derivation of it?
Input
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 1000) which is the number of test cases. And it will be
followed by Tconsecutive test cases.
There are exactly 2 lines in each test case. The first line of each test case is a single line containing an integer N (0 <= N <= 100). The second line contains N +
1 non-negative integers, CN, CN-1, ..., C1, C0, ( 0 <= Ci <= 1000), which are the coefficients of f(x). Ci is the coefficient of the term
with degree i in f(x). (CN!=0)
Output
For each test case calculate the result polynomial g(x) also in a single line.
(1) If g(x) = 0 just output integer 0.otherwise
(2) suppose g(x)= Cmx^m+Cm-1x^(m-1)+...+C0 (Cm!=0),then output the integers Cm,Cm-1,...C0.
(3) There is a single space between two integers but no spaces after the last integer.
Sample Input
Sample Output
题意:对方程求导,指数第一项是n,第二项是n-1
题解:直接模拟,这里如果n==1,直接输出0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
#define N 10000
int a
;
#define inf 0x3f3f3f3f
int main(){
#ifdef CDZSC
freopen("i.txt","r",stdin);
#endif
char s
;
int n,t,x;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n+1;i++)
{
scanf("%d",a+i);
}
if(n==0)
{
printf("0");
}
int tt=n;
for(int i=0;i<n;i++)
{
a[i]=a[i]*(tt);
tt--;
}
int fi=1;
for(int i=0;i<n;i++)
{
if(fi)
{
printf("%d",a[i]);
fi=0;
}
else
{
printf(" %d",a[i]);
}
}
printf("\n");
}
return 0;
}
Time Limit: 2 Seconds Memory Limit: 65536 KB
Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))' to denote its derivation. We use x^n to denote xn. To calculate the derivation
of a polynomial, you should know 3 rules:
(1) (C)'=0 where C is a constant.
(2) (Cx^n)'=C*n*x^(n-1) where n>=1 and C is a constant.
(3) (f1(x)+f2(x))'=(f1(x))'+(f2(x))'.
It is easy to prove that the derivation a polynomial is also a polynomial.
Here comes the problem, given a polynomial f(x) with non-negative coefficients, can you write a program to calculate the derivation of it?
Input
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 1000) which is the number of test cases. And it will be
followed by Tconsecutive test cases.
There are exactly 2 lines in each test case. The first line of each test case is a single line containing an integer N (0 <= N <= 100). The second line contains N +
1 non-negative integers, CN, CN-1, ..., C1, C0, ( 0 <= Ci <= 1000), which are the coefficients of f(x). Ci is the coefficient of the term
with degree i in f(x). (CN!=0)
Output
For each test case calculate the result polynomial g(x) also in a single line.
(1) If g(x) = 0 just output integer 0.otherwise
(2) suppose g(x)= Cmx^m+Cm-1x^(m-1)+...+C0 (Cm!=0),then output the integers Cm,Cm-1,...C0.
(3) There is a single space between two integers but no spaces after the last integer.
Sample Input
3 0 10 2 3 2 1 3 10 0 1 2
Sample Output
0 6 230 0 1
题意:对方程求导,指数第一项是n,第二项是n-1
题解:直接模拟,这里如果n==1,直接输出0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
#define N 10000
int a
;
#define inf 0x3f3f3f3f
int main(){
#ifdef CDZSC
freopen("i.txt","r",stdin);
#endif
char s
;
int n,t,x;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n+1;i++)
{
scanf("%d",a+i);
}
if(n==0)
{
printf("0");
}
int tt=n;
for(int i=0;i<n;i++)
{
a[i]=a[i]*(tt);
tt--;
}
int fi=1;
for(int i=0;i<n;i++)
{
if(fi)
{
printf("%d",a[i]);
fi=0;
}
else
{
printf(" %d",a[i]);
}
}
printf("\n");
}
return 0;
}
相关文章推荐
- Git入门及上传项目到github中
- Git入门及上传项目到github中
- 关于CSS样式的那些事_导航条菜单讲解
- k-means聚类算法
- VisualStudio代码格式化的几个方法
- 10个Jquery常用技巧+原生xhr对象的简单介绍
- EM算法
- JavaScript高级程序设计之DOM2和DOM3之样式之操作样式表第12.2.2讲
- Java面向对象编程-第6章学习笔记
- C/C++基础面试题
- dreamwaver cs6 主题配色方案
- Day 5(11.7):(3)运算符
- BZOJ3555: [Ctsc2014]企鹅QQ(字符串hash)
- 字符串删除指定字符
- ZOJ 2966 最小生成树(B)
- line-hight-(行高)解析
- 交换某个类里面的方法
- c++调用ado执行带参数的sql(非存储过程)
- CSS 属性 overflow 深入理解学习笔记
- 在动作栏(Action Bar)中添加和删除选项卡