Archive for the ‘ACM’ tag
[ZeroJudge] p001 Minesweeper
最近又開始覺得很無聊,所以要回去寫題目來練習,剛好就拿ZJ2的Minesweeper來小試一下,
這個題目就是要實作簡單版的採地雷(概念上),所以還蠻有趣的XD。
P.S. 我發現我之前寫ACM的文章都是用code tag包起來,但是只要沒有相對應的Css來搭配就真的是什麼都顯示不出來,有夠給他難看的…我晚點再來把他們都放上gist!
[計畫]想做的事
就在剛剛終於逃離了期末考的魔爪,現在要來列個清單是關於我整個寒假的計畫,能完成多少就多少吧。
- 讀書計畫
- read 愛上jQuery & 深入淺出 Ajax
- [Done]read Facebook:性愛與金錢、天才與背叛交織的祕辛
- read Introduction to Algorithms
- …增加中
- 工作計畫
- EatMe 主站規劃
- Hax4 主站規劃
- 畢業專題構思
- ACM解題
- …增加中
- 其餘活動
- 食我出遊
- [Done]資轉出遊
- 死黨聚會
- ??
- …增加中
結論就是,等著累死吧!!!!!
[PKU]1503 Integer_Inquiry
[ZeroJudge]p018 Polynomial coefficients
就是多項式係數計算的簡化版,因為X1 , X2 …. Xn 就只是個變數,不會有像
高中數學那樣,還要考慮因為次方而多產生的係數,算是蠻簡單的,只是這邊
用到Recursive的Factorial計算,他有故意限定是 (0<K,N<13),所以用
long long int 去算就可以了,沒有太多困難。
[UVa]944 Happy Numbers
要注意一下題目的換行是要在兩個output之間 , 最後一個output就不能送出 endline ..
[ACM] 3n+1
太久沒有寫code了 , 想說來寫寫練習一下 , 剛好看到有人的3n+1的code , 想說來寫個比較簡短的版本 , 直接recursive 下去做真的是方便時很多呢!
BTW , 我發現我真的很愛用三元運算子= =” , 清楚又短~
#include <stdio.h>
void cal(int,int);
int m_cal(int,int);
int main (int argc, const char * argv[]) {
int input1,input2;
while(scanf("%d%d",&input1,&input2)!=-1){
cal(input1,input2);
}
return 0;
}
int m_cal(int a,int length){
if(a==1){
return length;
}else if(a%2==1){
return m_cal(a*3+1,length+1);
}else{
return m_cal(a/2,length+1);
}
}
void cal(int a,int b){
int i=a>b?b:a,j=a>b?a:b;
int temp,memory=0;
for(i;i<=j;i++){
temp = m_cal(i,1);
memory = temp>memory ? temp:memory;
}
printf("%d %d %d\n",a,b,memory);
}
[ACM]412 Pi
1.先把π的公式由數學式導出來
2.要用到數學的排列組合(C X取2這樣)
3.算互質的個數
4.格式化輸出(精確到小數點下第六位)
心得:在算最後一步的時候(求π時) , 要小心那個double的地方 , 因為int
在算的時候會有拾去的情況 , 最好是都用同個型態去算 , 比較不會出問題
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int c_num(int i){
return (i*(i-1))/2;
}
void sort(int arr[],int num){
int i,j;
for(i=0;i<num-1;i++){
for(j=i+1;j<num;j++){
if(arr[i]<arr[j]){
swap(arr[i],arr[j]);
}
}
}
}
void swap(int* a,int* b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int judge(int a,int b){
int max = (a<b)?a:b;
int min = (a<b)?a:b;
int reminder,quotient;
reminder = max%min;
quotient = max/min;
while(reminder!=0){
max = min;
min = reminder;
quotient = max/min;
reminder = max%min;
}
return min;
}
int main(){
int i,j,k;
int arr[200],count;
while(cin >> i){
count = 0;
if(i==0){
return 0;
}else{
for(j=0;j<i;j++){
cin >> arr[j];
}
sort(arr,i);
for(j=0;j<i-1;j++){
for(k=j+1;k<i;k++){
if(judge(arr[k],arr[j])==1){
count++;
}
}
}
if(count==0){
cout << "No estimate for this data set." << endl;
}else{
printf("%.6lf\n",sqrt(((double)(6*c_num(i))/count)));
}
}
}
system("pause");
return 0;
}
[ACM] 最近在解ACM..
好久沒有解ACM了 , 我發現現在我要解一些題目 , 就感覺比較不會那麼的困擾了 …
現在是用ZeroJudge的線上解題系統來解題的 , 以後如果有解出的題目 , 除了一些
很簡單的不會放外 (像是什麼物理子彈那種= =) 其他的都會放上來一下:D
