發表文章

Excel 基礎入門

圖片

新北市單一簽入網站-sso.ntpc.edu.tw

圖片
新北市單一簽入網站 入口網站 https://sso.ntpc.edu.tw 教師:帳號、密碼(已自訂) 學生:帳號(已自訂)、密碼(預設值為身份證字號密碼大寫) ---- 同新北市校務行政系統---- office 365

UVA Q591:Box of Bricks

圖片
Q591:Box of Bricks 3 歲的小明喜歡玩他的方塊積木,他總是把方塊疊在一起形成高度不一的方塊堆。然後他說:這是一面牆。 5 歲的姊姊小美聽到了就跟小明說:真正的牆高度應該要一樣才行。小明聽了覺得有道理於是決定要搬動一些方塊使所有方塊堆的高度一樣。如下圖。由於小明是個懶惰的小孩,他想要搬動最小數目的方塊以達成這個目的,你能幫助他嗎?     Input 輸入包含好幾組資料,每組資料有 2 行,第一行有一個數字 n ,代表有幾堆方塊。第二行有 n 個數字分別代表這 n 堆方塊的高度 h i 。你可以假設 1<=n<=50  1<=h i <=100 方塊的總數一定可以整除堆數 n ,也就是說一定可以使所有的方塊堆同樣高度。 如果輸入的 n=0 ,代表輸入結束。   Output 對每一組輸入資料,首先輸出一行這是第幾組測試資料,下一行為 "The minimum number of moves is k." k 在這裡就是需搬動方塊最小的數目以使所有的方塊堆同一高度。每組測試資料後亦請空一行。請參考 Sample Output.  Sample Iutput 6 5 2 4 1 7 5 3 1 1 1 0 Sample Output Set #1 The minimum number of moves is 5. Set #2 The minimum number of moves is 0. #include<iostream> #include<math.h> #include<cstring> #include<iomanip> using namespace std; int main(){ int a,b[50],c,d,e=0; while(cin>>a){ e++; if(a==0){ break; } c=0; d=0; for(int x=0;x<a;x++){ cin>>b[x]; c=c+b[x]; } c=c/a; for(int x=0;x<...

TCGS b004: 一個都不能少

內容:   進德女子監獄座落於自由女中旁,是間作風開放的監獄,每到中午時間便會放風讓收容人到外面用餐。當然還是會有人逾時不歸,身為管理者的美惠,每天總是要為哪些人沒有回來而傷透腦筋。現在想請你寫一個程式,幫助美惠找出哪些人沒有回來。 輸入說明: 一開始有兩個正整數 N、M (0<=M<N<=20),N 代表收容人的人數(編號從 1 到 N),M 代表回來的人數,接下來有 M 個正整數,分別代表這 M 位已經回來的收容人編號(不用考慮編號超出範圍或其他錯誤)。 輸出說明: 請將沒有回來的收容人編號從小到大輸出,兩個編號中間請空一格。 範例輸入: 輸入1: 4 3 1 2 3 輸入2: 5 3 5 3 1 範例輸出 : 輸出1: 4 輸出2: 2 4 程式碼 : #include <iostream> using namespace std; int main() { int a,n,b,c[20]; cin>>a>>n; for(int x=0;x<a;x++){ c[x]=x+1; } for(int x=0;x<n;x++){ cin>>b; c[b-1]=0; } for(int x=0;x<a;x++){ if(c[x]!=0){ cout<<c[x]<<" "; } } system("PAUSE"); return 0; }

UVA Q11614 - Etruscan Warriors Never Play Chess

圖片
這題我是用 等差級數 然後再用一元二次方的 公式解 解題的(一元二次方程式求出來的值若非整數直接無條件捨去)。 程式碼 : #include<iostream> #include<cmath>//sqrt()(平方根)的函數庫 using namespace std; int main(){ long long int n,b,c; cin>>c;//輸入有幾個測資 for(int x=0;x<c;x++){//連續輸入 cin>>n;//連續輸入 b=((-1)+sqrt(1+(8*n)))/2;//用公式解解 cout<<b<<endl;//輸出答案 } system ("pause"); return 0; }

UVA Q12405 - Scarecrow

            這題是 貪婪解法 ,在陣列依依搜尋,如果遇到良田(.),就在良田後一塊地建一個稻草人,所以被搜尋到的那塊良田與接下來的兩塊地都被保護到了,所以一搜尋到良田就直接 跳到後三格 並繼續搜尋直到結束,這樣就知道最少要放幾個稻草人了。 程式碼 : #include<iostream> using namespace std; int main(){ int a,b,d; char c[100]; cin>>a;// 輸入有幾組測資 for(int x=1;x<=a;x++){//連續輸入         cin>>b;//輸入陣列有幾項 cin>>c;//輸入陣列 d=0;//初始化d(稻草人數 ) for(int y=0;y<b;y++){//搜尋陣列裡的良田 if(c[y]=='.'){//當遇到良田 d++;//有幾個稻草人 y=y+2;// 跳三格(包括for迴圈裡的y++) } } cout<<"Case "<<x<<": "<<d<<endl;//輸出這是第幾組測資(x)與最少要見幾個稻草人(d) }  system("pause"); return 0; }

2013 國中組初賽-題目 A 挑食的大胃王

[解法ㄧ] #include<iostream> using namespace std; int main(){ int T,M,N,K,ans; cin>>T; while(T--){ ans=0; cin>>M>>N>>K; int eat[M][N]; for(int i=0;i<M;i++){            //輸入原始陣列值 for(int j=0;j<N;j++){ cin>>eat[i][j]; } } for(int i=0;i<M;i++){ for(int j=0;j<N;j++){ if(eat[i][j]%2==1){          //除以2餘數等於1 if(i-1>=0)               //將會被挖掉的位置確定 eat[i-1][j]+=2;     //eat[i][j]=eat[i][j]+2 if(j-1>=0) eat[i][j-1]+=2; if(i+1<M) eat[i+1][j]+=2; if(j+1<N) eat[i][j+1]+=2; eat[i][j]+=2; } } } for(int i=0;i<M;i++){               //計算出會被挖掉的值 for(int j=0;j<N;j++){ if(eat[i][j]){ ans++;                  //ans=ans+1 ...

使用memset加快二維陣列初始

一般方法是用雙迴圈來設定二維陣列的值 這裡使用memset來設定陣列初值 #include   <cstring> const   int  X_SIZE  =   60 ; const   int  Y_SIZE  =   30 ; int  matrix [ X_SIZE ][ Y_SIZE ]; inline   void  init_matrix ()   //使用inline加快 {    //設定陣列內的值全為-1   memset ( matrix ,   - 1 ,   sizeof ( matrix ));   } PS: memset(matrix, 1, sizeof(matrix)); //會失敗 memset為字元填入的函式,整數由2或4個位元組(字元)組成 設定的值是0x01,但存入的值卻是0x0101,而導致錯誤的答案 而-1則是0xFF,存入的值是0xFFFF,不會影響答案 原始文章出處: http://jhengjyun.blogspot.tw/2010/02/cc-memset.html

如何trace code & debug

如何trace code & debug

讓EXCEL參照的工作表內,空格不顯示為0

公式是  ='Sheet01'!A1 只是當[Sheet01]A1格為空格的時候,[Sheet01]A1格會顯示為0 如何讓[Sheet01]A1格忠實呈現為空格呢? 請利用  =IF(Sheet01!A1="","",Sheet01!A1)

文字遮色片

圖片

延遲時間

延遲一秒 寫法一: Sleep(1000); 寫法二: for (int delay=0; delay<=10000; delay++) 寫法三: time_t t1 = time(NULL), t2; do { t2 = time(NULL); } while((t2-t1)<1;

for 巢狀迴圈

#include #include #include using namespace std; int main(int argc, char *argv[]) { int multiplier, faciend; for (faciend=1; faciend

for 迴圈

基本型 int sum=0; for (int count=1; count 簡化型 int sum=0; for (int count=1; count 省略型 int sum=0, count=1; for ( ; count=1; count 單行型 int count, sum; for (count=1, sum=0; count

while巢狀迴圈 數字三角形

#include #include #include using namespace std; int main(int argc, char *argv[]) { int outer = 0; while (outer++

do-while巢狀迴圈 數字三角形矩陣

#include #include #include using namespace std; int main(int argc, char *argv[]) { int outer = 1; do { int inner = 1; do { cout

兩數除法(判斷大小及除數是否為0)

#include #include using namespace std; int main(void) { int a, b; cout << "請輸入二個整數數值,以空白分隔:"; cin >> a >> b; if(a >= b) { if(b == 0) cout << "除數為 0\n"; else cout << a << " / " << b << " = " << (float)a/(float)b << endl; } else { if(a == 0) cout << "除數為 0\n"; else cout << b << " / " << a << " = " << (float)b/(float)a << endl; } return 0; }

判斷直角、鈍角或銳角三角形(II)

#include #include #include using namespace std; int main(int argc, char *argv[]) { float a, b, c; cout > a >> b >> c; if((a+b)>c && (b+c)>a && (c+a)>b) { if(pow(a,2) + pow(b,2) == pow(c,2) || pow(b,2) + pow(c,2) == pow(a,2) || pow(c,2) + pow(a,2) == pow(b,2)) cout pow(c,2) && pow(b,2) + pow(c,2) > pow(a,2) && pow(c,2) + pow(a,2) > pow(b,2)) cout

判斷直角、鈍角或銳角三角形(I)

#include #include #include using namespace std; int main(int argc, char *argv[]) { float a, b, c, d; cout << "請輸入三角形三邊邊長,以空白分隔:"; cin >> a >> b >> c; d = (pow(a,2)+pow(b,2)-pow(c,2))*(pow(b,2)+pow(c,2)-pow(a,2))*(pow(a,2)+pow(c,2)-pow(b,2)); if (d == 0 && (a+b)>c && (b+c)>a && (c+a)>b) cout << a << ' ' << b << ' ' << c << " 三邊構成直角三角形\n"; else if (d > 0 && (a+b)>c && (b+c)>a && (c+a)>b) cout << a << ' ' << b << ' ' << c << " 三邊構成銳角三角形\n"; else if (d < 0 && (a+b)>c && (b+c)>a && (c+a)>b) cout << a << ' ' << b << ' ' << c << " 三邊構成鈍角三角形\n"; else cout << a << ' ' << b << ' ' << c <...

判斷三角形三邊邊長是否構成三角形

1.利用兩邊長和必須大於第三邊,而且需檢驗三次同時成立。 #include #include #include using namespace std; int main(int argc, char *argv[]) { float a, b, c; cout << "請輸入三角形三邊邊長,以空白分隔:"; cin >> a >> b >> c; if((a+b)>c && (b+c)>a && (c+a)>b) cout << a << ' ' << b << ' ' << c << " 三邊構成三角形\n"; else cout << a << ' ' << b << ' ' << c << " 三邊不構成三角形\n"; system("PAUSE"); return EXIT_SUCCESS; } 2.利用兩邊和大於第三邊且兩邊差的絕對值小於第三邊。 #include #include #include using namespace std; int main(int argc, char *argv[]) { float a, b, c; cout << "請輸入三角形三邊邊長,以空白分隔:"; cin >> a >> b >> c; if((a+b)>c && abs(a-b)