close
題目概要:
計算出微分後的數字。
解題方向:
直接依微分的方式打成程式碼。
Ps. Uva OnlineJudge 輸入x之後所輸入的係數可能會有連續空白 Ex 1△2△3△△4....(△=空白),因為我這個問題runtime error(RE)很多次。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
} | |
} |
文章標籤
全站熱搜