EragonJ's World

About me

Archive for the ‘ACM’ Category

[ZeroJudge] p001 Minesweeper

without comments

最近又開始覺得很無聊,所以要回去寫題目來練習,剛好就拿ZJ2的Minesweeper來小試一下,

點我看題目

這個題目就是要實作簡單版的採地雷(概念上),所以還蠻有趣的XD。

P.S. 我發現我之前寫ACM的文章都是用code tag包起來,但是只要沒有相對應的Css來搭配就真的是什麼都顯示不出來,有夠給他難看的…我晚點再來把他們都放上gist!

Written by admin

February 2nd, 2010 at 2:37 pm

Posted in ACM

Tagged with , , , , ,

[PKU]1503 Integer_Inquiry

without comments

我寫到快殺人了…

其實這題我一直都寫好了,但是就一直WA,最該死的就是我不知道問題在哪…也看了很多討論,但是就不知道錯在哪,有心的幫幫我一下吧..


PKU的測試位置(要帳號)

Written by admin

December 11th, 2009 at 1:05 pm

Posted in ACM

Tagged with , , ,

[ZeroJudge]p018 Polynomial coefficients

without comments

就是多項式係數計算的簡化版,因為X1 , X2 …. Xn 就只是個變數,不會有像
高中數學那樣,還要考慮因為次方而多產生的係數,算是蠻簡單的,只是這邊
用到Recursive的Factorial計算,他有故意限定是 (0<K,N<13),所以用
long long int 去算就可以了,沒有太多困難。

Written by admin

December 4th, 2009 at 6:52 pm

Posted in ACM

Tagged with ,

[UVa]944 Happy Numbers

without comments

要注意一下題目的換行是要在兩個output之間 , 最後一個output就不能送出 endline ..

Written by admin

November 27th, 2009 at 6:15 pm

Posted in ACM

Tagged with , ,

[ACM] 3n+1

with 2 comments

太久沒有寫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);
}

Written by admin

March 24th, 2009 at 2:36 am

Posted in ACM

Tagged with ,

[ZeroJudge] a010 因數分解

without comments

這題也是有點有趣 , 不過我自己的做法比較笨一點 ,
就是先開個可以容的下題目的array[1000000] , 然後
去存哪些因數有算過就++ , 最後再去總結算 !

要注意的地方:
1.我用了recursive的方法去實做
2.用search function 去找有x個格子的數字不是0 (x-1就是乘號的數目)

大概就是這樣! 如果有什麼比較好的方法請提供一下:D


#include <iostream>
#define MAX 1000000
using namespace std;
int arr[MAX]={0};
void div(int input){
int i;
int sinput = input;
for(i=2;i<=sinput;i++){
if(sinput%i==0){
arr[i]+=1;
sinput/=i;
break;
}
}
if(input!=sinput){
div(sinput);
return ;
}
}
void reset(){
int i;
for(i=0;i<MAX;i++){
arr[i]=0;
}
}
int search(){
int i,count=0;
for(i=2;i<MAX;i++){
if(arr[i]!=0) count++;
}
return count;
}
int main(){

int h,i,k,scount=0;

while(cin >> i){
div(i);
scount = search()-1;
for(k=2;k<MAX;k++){
if(arr[k]!=0){
if(arr[k]==1){
cout << k ;
}else{
cout << k << "^" << arr[k] ;
}
if(scount!=0){
cout << " * " ;
scount--;
}
}
}
cout << endl;
reset();
}
system("pause");
return 0;
}

Written by admin

January 22nd, 2009 at 10:24 am

Posted in ACM

Tagged with , ,

[ACM]412 Pi

without comments


這題比較要注意的地方有以下幾點:

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;
}

Written by admin

January 22nd, 2009 at 6:07 am

Posted in ACM

Tagged with , ,

[ACM] 最近在解ACM..

without comments

好久沒有解ACM了 , 我發現現在我要解一些題目 , 就感覺比較不會那麼的困擾了 …

現在是用ZeroJudge的線上解題系統來解題的 , 以後如果有解出的題目 , 除了一些

很簡單的不會放外 (像是什麼物理子彈那種= =) 其他的都會放上來一下:D

Written by admin

January 22nd, 2009 at 6:04 am

Posted in ACM

Tagged with