跳到主要內容

發表文章

目前顯示的是有「未分類」標籤的文章

ZeroJudge b898

ZeroJudge b898  : https://zerojudge.tw/ShowProblem?problemid=b898 /*large number*/ #include <iostream> #include <string> using namespace std; int main(int argc, const char * argv[]) {         // your code goes here     int count = 0;     cin>>count;     while(count--)     {         /*initial*/         string fir,sec,thi;                 cin>>fir>>sec>>thi;         string temp[3];         temp[0]=fir;         temp[1]=sec;         temp[2]=thi;                 string ans =temp[0];                 for(int i =1;i<3;i++)         {             if(ans.size()>temp[i].size...

ITSA_38_Pro5

[Problem 5] Pseudo Random Generation 成績: 0 / 倒扣: 0.8 Problem Description Random numbers are usually used in computer program. Computer can't produce pure random numbers but can produce pseudo random numbers. There are some pseudo random generators in our program language library which are usually used. There is a method which is usually used to produce pseudo random numbers. The method is called linear congruential method. This method needs 4 parameters: m   a   c   X 0 a modulus   a multiplier   a addend   a initial number(seed number) m   > 0 0 <   a   <   m 0 ≤   c   <   m 0 ≤   X 0   <   m The pseudo random numbers are produced by follow program states:   X n +1   = (   aX n   +   c   ) mod   m   For example, if   a   = 7,   c   = 5,   m   =12, and   X 0   = 4 then the program produces ...

ITSA_C_DP_18

[C_DP18-中] 沙漠綠洲 成績: 0 / 倒扣: 0.8 問題描述:  在沙漠中有一個村落,村落旁邊有一個綠洲,村民所有的水都要從綠洲取得,村長發給每一戶人家一個水桶,以及家中每個人一個水瓢,年齡愈大的人拿到的水瓢容積愈大,並且規定每戶人家每天只能只能裝一桶水,取水時必須排隊,每個人一次只能舀一瓢水,而且水瓢必須裝滿。今天小明全家出動,要去裝水,知道水桶可裝  M  公升的水, 請幫小明算算全家人如何在排最少舀水幾次能將水桶裝滿,而綠洲的水相當珍貴,所以不能讓水滿出水桶。 輸入說明:  第一行有一個正整數  N  ,表示共有  N  筆測試資料,之後有  N  行,每行為一筆測試資料。每筆測資第一個數為一個正整數  K  (1 <=  K  <= 100) ,代表家中人口數 ( 即水瓢的數量 ) ,之後有  K  +1 個正整數,前面  K  個數字分別代表各水瓢的容積,最後一個則代表水桶的容積 (M <= 10000),每個整數間均有一個空格隔開。 輸出說明:  每筆測試資料 輸出最少舀水次數 於一行,若無法在不溢出的情況下 將水桶裝滿則輸出 0 。 範例 Sample Input     Sample Output 2 3 2 3 4 5 4 2 4 6 8 21     2     0 解法:動態規劃 import java.util.Scanner; public class ITSA_C_DP18 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for (int n = 0; n < N; n++) { ...