close

題目概要:

計算出微分後的數字。

解題方向:

直接依微分的方式打成程式碼。

Ps. Uva OnlineJudge 輸入x之後所輸入的係數可能會有連續空白 Ex 1△2△3△△4....(△=空白),因為我這個問題runtime error(RE)很多次。

程式碼:

//Java
import java.util.Scanner;
class main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
while(sc.hasNextLine()){
long x=Long.parseLong(sc.nextLine());
String an[]=sc.nextLine().split("\\s+"); //跳過多個空白鍵
long ans=0;
long xp=1;
for(int i=an.length-2;i>=0;i--,xp*=x){
ans+=Long.parseLong(an[i])*(an.length-1-i)*xp; //微分計算
}
//Output
System.out.println(ans);
}
}
}
view raw uva10268.java hosted with ❤ by GitHub

arrow
arrow
    文章標籤
    Java
    全站熱搜
    創作者介紹
    創作者 a7069810 的頭像
    a7069810

    紀錄自己的程式人生

    a7069810 發表在 痞客邦 留言(0) 人氣()