網頁

2012年7月23日 星期一

b210. C. 咒語

/**********************************************************************************/
/*  Problem: b210 "C. 咒語" from 2008 NPSC 高中組決賽                      */
/*  Language: CPP (1187 Bytes)                                                    */
/*  Result: AC(2.8s, 8.3MB) judge by this@ZeroJudge                               */
/*  Author: monkey413 at 2012-07-23 15:10:08                                      */
/**********************************************************************************/


//參考自:https://sites.google.com/a/hpsh.co.cc/code/ti-mu/b210-c
#include<iostream>
#define N 10001
#define swap(a,b){t=a,a=b,b=t;}
using namespace std;
class edge    // 每個點連結出去的邊
{
    public:
        int from ;
        int value ;
};
class node
{
    public:
        edge passage[100] ;
};
node map[N] ;
int top[N]={0} ; // 點的連結個數
unsigned long long int ans[N] ;
int n,m,x,y,z,t,newp;
int main()
{
    while(cin>>n>>m)
    {
        if(!n&&!m) break ;
        for(int i=0 ; i<m ; ++i)
        {
            cin >> x >> y >> z ;
            if(x>y) swap(x,y) ;
            top[y]++ ;
            map[y].passage[top[y]].from=x ;
            map[y].passage[top[y]].value=z ;
        }
        for(int i=1 ; i<=n ; ++i)
        {
            ans[i]=ans[i-1] ; //當沒有點連結到i點時
            for(int j=1 ; j<=top[i] ; ++j)
            {
                newp=ans[map[i].passage[j].from]+map[i].passage[j].value ;
                ans[i]=(ans[i]>newp?ans[i]:newp) ;
            }
        }
        cout << ans[n] << endl ;
        for(int i=0 ; i<=n ; ++i) top[i]=0 ;
    }
    return 0 ;
}

a293. A 百年國慶

/**********************************************************************************/
/*  Problem: a293 "A 百年國慶" from 2011 NPSC 國中組初賽                 */
/*  Language: CPP (1081 Bytes)                                                    */
/*  Result: AC(108ms, 372KB) judge by this@ZeroJudge                              */
/*  Author: monkey413 at 2012-07-23 15:54:02                                      */
/**********************************************************************************/


#include<iostream>
#define N 5
using namespace std;
int n,sum=0;
int arr[N][N];
int tmp[N][N];
int main()
{
    while(cin>>n)
    {
        for(int i=0 ; i<n ; ++i)
        {
            for(int j=0 ; j<N ; ++j) for(int k=0 ; k<N ; ++k) cin >> arr[j][k] ;
            if(i)
            {
                for(int a=0 ; a<N ; ++a)
                {
                    for(int b=0 ; b<N ; ++b)
                    {
                        if(tmp[a][b]==1 && arr[a][b]==1)
                            sum+=1 ;
                        else if(tmp[a][b]==1 && arr[a][b]==8)
                            sum+=7 ;
                        else if(tmp[a][b]==8 && arr[a][b]==1)
                            sum+=2 ;
                        else if(tmp[a][b]==8 && arr[a][b]==8)
                            sum+=5 ;
                    }
                }
                cout << sum << endl ;
            }
            for(int j=0 ; j<N ; ++j) for(int k=0 ; k<N ; ++k) tmp[j][k]=arr[j][k] ;
            sum=0 ;
        }
    }
    return 0 ;
}

a241. 第二題:1 / x 是有限小數

/**********************************************************************************/
/*  Problem: a241 "第二題:1 / x 是有限小數" from 板橋高中2011能力競賽*/
/*  Language: CPP (779 Bytes)                                                     */
/*  Result: AC(4ms, 380KB) judge by this@ZeroJudge                                */
/*  Author: monkey413 at 2012-07-23 11:20:59                                      */
/**********************************************************************************/


#include<iostream>
#include<algorithm>
using namespace std;
int m,n,top=0,upper;
int arr[1000] ;
long long int t=1 ;
int power(int base, int exp)
{
    int tmp=1 ;
    while(exp)
    {
        if(exp&1) tmp*=base ;
        base*=base ;
        exp>>=1 ;
    }
    return tmp ;
}
int main()
{
    for(int i=0 ; i<=13 ; ++i)
    {
        t=power(5,i);
        for(int j=0 ; j<=30; ++j)
        {
            if(t>1000000000) break ;
            else arr[top++]=t ;
            t*=2 ;
        }
    }
    sort(arr,arr+top) ;
    while(cin>>m)
    {
        for(int i=0 ; i<m ; ++i)
        {
            cin >> n ;
            upper=upper_bound(arr,arr+top,n)-arr;
            cout << upper-1 << endl ;
        }
    }
    return 0 ;
}

2012年7月22日 星期日

今天上山挖竹筍去

早上七點多,就被我媽呼叫起來上山挖竹筍。上山後,我拿著一把小菜刀想盡辦法的將竹筍給切下來,竹筍真的很硬,我的小菜刀根本沒有辦法切下去,最後我使出吃奶的力氣才好不容易將竹筍給切下來,想想有切竹筍用的剉刀還是比較好用的說!

2012年7月21日 星期六

開張大吉

原部落格在monkey413.wordpress.com,但是我覺的wordpress.com的東西完全不能修改,讓我覺得有點無聊,所以我就將部落格搬到monkey413.blogspot.tw。:)

a251: 假費波那契數

 /**********************************************************************************/
/*  Problem: a251 "假費波那契數" from 成功高中校內賽初賽 第一題 */
/*  Language: CPP (365 Bytes)                                                     */
/*  Result: AC(4ms, 374KB) judge by this@ZeroJudge                                */
/*  Author: monkey413 at 2012-07-21 11:10:34                                      */
/**********************************************************************************/
#include<iostream>
#include<algorithm>
using namespace std;
int T,N;
int table[20];
int main()
{
 while(cin>>T)
 {
  for(int i=0 ; i>N ;
   for(int j=0 ; j> table[j];
   for(int j=4 ; j<N ; ++j) table[j]=table[j-4]+table[j-1] ;
   sort(table,table+N) ;
   cout << table[N/2] << endl ;
  }
 }
 return 0;
}
簡易DP

d501. 第二題:數列最小值

/**********************************************************************************/
/*  Problem: d501 "第二題:數列最小值" from 高雄市98資訊學科能力競賽*/
/*  Language: CPP (414 Bytes)                                                     */
/*  Result: AC(516ms, 4.3MB) judge by this@ZeroJudge                              */
/*  Author: monkey413 at 2012-07-21 09:59:22                                      */
/**********************************************************************************/


#include<iostream>
#include<algorithm>
using namespace std;
int n ;
int main()
{
    while(cin>>n)
    {
        int num[n] ;
        for(int i=0 ; i<n ; ++i) cin >> num[i] ;
        sort(num,num+n) ;
        if(n%2) cout << "A=" << num[n/2] ;
        else
        {
            cout << "A=" ;
            for(int i=num[n/2-1] ; i<=num[n/2] ; ++i)
            {
                cout << i ;
                if(i!=num[n/2]) cout << "、" ;
            }
        }
        cout << endl ;
    }
    return 0;
}

2012年7月20日 星期五

今日種田日

最近我媽愛上了種田,所以我也只能跟著我媽去種田了,種田真的好累,割雜草、澆水、屯田、……樣樣都得來,禮拜天還要去挖竹筍,看來這個暑假我過的十分的不平靜。//我想寫程式和部落格~~~

a227. 三龍杯 -> 河內之塔

/**********************************************************************************/
/*  Problem: a227 "三龍杯 -> 河內之塔" from 2011三龍杯 (成附建杯)   */
/*  Language: C (429 Bytes)                                                       */
/*  Result: AC(9ms, 298KB) judge by this@ZeroJudge                                */
/*  Author: monkey413 at 2012-07-20 21:16:26                                      */
/**********************************************************************************/
#include<iostream>
void hanoi(int n, char A, char B, char C)
{
    if(n==1) printf("Move ring %d from %c to %c\n",n,A,C) ;
    else
    {
        hanoi(n-1,A,C,B) ;
        printf("Move ring %d from %c to %c\n",n,A,C) ;
        hanoi(n-1,B,A,C) ;
    }
}
int n;
int main()
{
    while(scanf("%d",&n)==1)
    {
        hanoi(n,'A','B','C');
        printf("\n") ;
    }
    return 0;
}
這題讓我瞭解到了遞迴的強大了!!

2012年7月19日 星期四

d526: Binary Search Tree (BST)

~/Desktop/kk.cpp.html
/**********************************************************************************/
/*  Problem: d526 "Binary Search Tree (BST)" from BST                             */
/*  Language: CPP (950 Bytes)                                                     */
/*  Result: AC(80ms, 1.6MB) judge by this@ZeroJudge                               */
/*  Author: monkey413 at 2012-07-19 13:32:31                                      */
/**********************************************************************************/
#include<iostream>
#include<cstdlib>
using namespace std ;
class Node
{
    public:
        int value ;
        Node* left;
        Node* right;
};
Node* root;

void Add_Node_To_Tree(Node** curr, int data)
{
    if(*curr==NULL)
    {
        Node* tmp=new node ;
        //tmp=(Node*)malloc(sizeof(Node)); 
        tmp->value=data,tmp->left=NULL,tmp->right=NULL ;
        *curr=tmp ;
    }
    else if(data<(*curr)->value) Add_Node_To_Tree(&((*curr))->left,data) ;
    else if(data>(*curr)->value) Add_Node_To_Tree(&((*curr))->right,data);
}
void pre(Node* ptr)
{
    if(ptr!=NULL)
    {
        cout << ptr->value << " " ;
        pre(ptr->left) ;
        pre(ptr->right) ;
    }
}
int n ;
int main()
{
    while(cin>>n)
    {
        int num[n] ;
        root=NULL ;
        for(int i=0 ; i<n ; ++i) cin >> num[i], Add_Node_To_Tree(&root,num[i]) ;
        pre(root) ;
        cout << endl ;
    }
    return 0;
}

暑假努力學習中!!!

暑假好長,想自己寫網頁,可是又找不到什麼好的免費網頁空間,只能用自己的電腦架一個apache伺服器來寫網頁,寫的好累~~,想想還是來做部落格,一個屬於自己的日記。