• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            哇哦~這就是我

            This is my way ~
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統(tǒng)計(jì)

            • 隨筆 - 10
            • 文章 - 0
            • 評(píng)論 - 2
            • 引用 - 0

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            2008年5月28日

            push!

            #include<iostream>
            #include<queue>
            #include<cmath>
            using namespace std;
            struct NODE
            {
             int p_x,p_y,step,c_x,c_y,d;
            };
            queue<NODE> que;
            const int MAXN = 100;
            bool p[MAXN][MAXN][4],c[MAXN][MAXN];
            int map[MAXN][MAXN];
            int mv[4][2]={-1,0,0,1,1,0,0,-1},p_sm,p_sn,c_sm,c_sn,m,n;
            void init ( )
            {
             memset(p,false,sizeof(p));
             for ( int i=0 ; i<m ; i++ )
              for ( int j=0 ; j<n ; j++ )
              {
               scanf("%d",&map[i][j]);
               if ( map[i][j]==4 )
                p_sm=i,p_sn=j;
               else
                if ( map[i][j]==2 )
                 c_sm=i,c_sn=j;
              }
            }
            int bfs ( )
            {
             NODE temp,go;
             int i;
             temp.p_x = p_sm;
             temp.p_y = p_sn;
             temp.c_x = c_sm;
             temp.c_y = c_sn;
             temp.step = 0;
             temp.d=0;
             for ( i=0 ; i<4 ; i++ )
             {
              p[p_sm][p_sn][i]=true;
              temp.d=i;
              que.push(temp);
             }
             c[c_sm][c_sn]=true;
             while ( !que.empty () )
             {
              NODE head=que.front();
              que.pop() ;
              for ( i=0 ; i<4 ; i++ )
              {
               int tm=head.p_x+mv[i][0] , tn=head.p_y+mv[i][1] ;
               if ( tm>=0 && tm<m && tn>=0 && tn<n && !p[tm][tn][i] && i!=(head.d+2)%4 && map[tm][tn]!=1 )
               {
                double t=sqrt( (double)( (tm-head.c_x)*(tm-head.c_x) ) +(double)( (tn-head.c_y)*(tn-head.c_y) ));
                if ( t <= sqrt(2.0) && t>0 )
                {
                 go=head;
                 go.p_x = tm;
                 go.p_y = tn;
                 go.step ++ ;
                 go.d=i;
                 p[tm][tn][i]=true;
                 que.push(go);
                }
                else
                {
                 int tmm=tm+mv[i][0] , tnn=tn+mv[i][1];
                 if ( t==0 && tmm>=0 && tmm<m && tnn>=0 && tnn<n && map[tmm][tnn]!=1 && !c[tmm][tnn] )
                 {
                  go.c_x = tmm ;
                  go.c_y = tnn ;
                  go.p_x = tm;
                  go.d=i;
                  go.p_y = tn;
                  go.step = head.step+1;
                  if ( map[tmm][tnn]==3 )
                   return go.step ;
                  c[tmm][tnn]=true;
                  p[tm][tn][i]=true;
                  que.push(go);
                 }
                }
               }
              }
             }
             return -1;
            }
            int main ( )
            {
             while ( scanf("%d%d",&n,&m)!=EOF )
             {
              init();
              printf("%d\n",bfs());
             // que.

             }
            }

            posted @ 2008-05-28 01:36 chinaeli 閱讀(197) | 評(píng)論 (0)編輯 收藏

            2008年5月7日

            11

            #include<iostream>
            #include<string>
            using namespace std;
            class FIELDDiagrams
            {
             public:
              void dfs ( int k, int max, int n , long long& sum ,  int a )
              {
               int i;
               if ( max==n )
               {
                sum++;
                return;
               }
               if (( k-1)*a+1<max-n )
                return ;
               for ( i=a ; i>=1   ; i-- )
                dfs(k-1,max,n+i ,sum , i );
              }
              long long countDiagrams ( int t )
              {
               long long map[40][40],sum=0,i;
               memset(map,0,sizeof(map));
               for ( i=1 ; i<=t*(t-1)/2 ; i++ )
                dfs( t, i,0,sum, i );
               return sum;
              }
            }; 
            int main ( )
            {
             FIELDDiagrams a;
             int n;
             while (cin>>n)
              cout<<a.countDiagrams (n)<<endl;
            }


             

            posted @ 2008-05-07 00:22 chinaeli 閱讀(200) | 評(píng)論 (0)編輯 收藏

            2008年4月16日

            第七次

            #include"cqueue.h"
            #include
            <iostream>
            void char_queue::enqueue(char d)
            {
                
            if ( tail>=max )
                    throw ( bad_op( ) );
                
            else
                    c[tail
            ++]=d;
            }
            char char_queue::dequeue()
            {
                return c[head
            ++];
            }
            int char_queue::isEmpty()
            {
                return head
            ==tail?1:0;
            }

            #include<cstdio>
            class char_queue
            {
                
            int head,tail,max;
                char c[
            10000];
            public:
                char_queue() {head
            =0; tail=0; max=10000; }
                void enqueue( char );
                char dequeue( );
                
            int isEmpty();
                class bad_op
                {
                
            public :
                    
            int type ;
                    bad_op(  ) { type
            =1 ; }
                };

            };

            posted @ 2008-04-16 23:27 chinaeli 閱讀(183) | 評(píng)論 (0)編輯 收藏

            2008年4月3日

            C++第五次上機(jī)作業(yè)

             

            #include<iostream>
            #include
            <sstream>
            #include
            <map>
            #include
            <string>
            #include
            <vector>
            #include
            <iomanip>
            #include
            <fstream>
            using namespace std;
            typedef map
            < string , vector<int> > WORD;
            void init ( WORD 
            & m )
            {
             ifstream fin;
             fin.open(
            "keywords.txt");
                
            string keyword;
                
            while ( fin>>keyword )
                    m[keyword];
             fin.close();
            }
            void count ( WORD 
            & m )
            {
                
            int line=0;
             ifstream fin;
             fin.open(
            "text.txt");
                
            string str;
                
            while ( getline(fin,str) )
                {
                    stringstream SS(str);
                    line
            ++;
                    
            while(SS>>str)
                    {
                        
            if ( m.find(str)!=m.end() )
                            m[str].push_back (line);
                    }
                }
             fin.close();
            }
            void output ( WORD m )
            {
                
            string keyword;
                
            for ( WORD::iterator iter_map=m.begin() ; iter_map!=m.end() ; iter_map++ )
                {
                    cout
            <<setw(10)<<iter_map->first<<":"
                        
            <<"(";
                    
            for ( vector<int>::iterator iter_vector=iter_map->second.begin() ; iter_vector!=iter_map->second.end(); iter_vector++ )
                    {
                        
            if ( iter_vector!=iter_map->second.begin() )
                            cout
            <<",";
                        cout
            <<*iter_vector;
                    }
                    cout
            <<")"<<endl;
                }
            }
            int main  ()
            {
                WORD m;
                init(m);
                count(m);
                output(m);
            }

            posted @ 2008-04-03 23:10 chinaeli 閱讀(322) | 評(píng)論 (1)編輯 收藏

            2008年4月2日

            C++第五次上機(jī)作業(yè)(提高)

             

            #include<iostream>
            #include
            <sstream>
            #include
            <map>
            #include
            <string>
            #include
            <vector>
            #include
            <iomanip>
            #include
            <fstream>
            #include
            <algorithm>
            using namespace std;
            typedef map
            < string , vector<int> > WORD;
            void init ( WORD 
            & m )
            {
             ifstream fin;
             fin.open(
            "keywords.txt");
                
            string keyword;
                
            while ( fin>>keyword )
                    m[keyword];
             fin.close();
            }
            void count ( WORD 
            & m )
            {
                
            int line=0;
             ifstream fin;
             fin.open(
            "text.txt");
                
            string str;
                
            while ( getline(fin,str) )
                {
              line
            ++;
              
            for ( WORD::iterator iter = m.begin () ; iter!=m.end( ); iter++ )
               
            if ( str.find ( iter->first )!=string::npos )
                m[iter
            ->first].push_back(line);
                }
             fin.close();
            }
            void only( WORD 
            &m )
            {
             
            for ( WORD::iterator i=m.begin() ; i!=m.end(); i++ )
             {
              vector
            <int>::iterator  new_end=unique(i->second.begin(),i->second.end());   
              i
            ->second.erase(new_end,i->second.end());   
             }
            }
            void sort_list ( WORD m , map
            <int,string> &mm )
            {
             
            for ( WORD::iterator iter_m = m.begin() ; iter_m != m.end() ; iter_m++ )
              mm[iter_m
            ->second .size ()]=iter_m->first; 
            }
            void output ( WORD m , map
            <int,string> mm )
            {
                
            string keyword;
             
            for ( map<int,string>::reverse_iterator iter=mm.rbegin() ; iter!=mm.rend() ; iter++ )
                {
                    cout
            <<setw(10)<<iter->second<<":"
                        
            <<"(";
              
            for ( vector<int>::iterator iter_vector=m[iter->second].begin() ; iter_vector!=m[iter->second].end(); iter_vector++ )
                    {
                        
            if ( iter_vector!=m[iter->second].begin() )
                            cout
            <<",";
                        cout
            <<*iter_vector;
                    }
                    cout
            <<")"<<endl;
                }
            }
            int main  ()
            {
                WORD m;
             map
            <int , string> mm;
                init(m);
                count(m);
             sort_list(m,mm);
             only(m);
                output(m,mm);
            }

            posted @ 2008-04-02 23:21 chinaeli 閱讀(244) | 評(píng)論 (0)編輯 收藏

            2008年3月31日

            我恨死這道題了。。。。。。

            我就是不理解這個(gè)投票規(guī)則,對(duì)這題整整困惑了12個(gè)小時(shí),從下午5點(diǎn)到凌晨5點(diǎn)。。。。。。。
            Long March Voting 

            Description

            Instant run-off voting is a system for selecting the most preferred candidate in an election. At the beginning of the process, each voter ranks the candidates from most preferred to least preferred. A series of automated voting rounds are then held to determine the overall winner.

            In each round, each voter casts a single vote for his most preferred remaining candidate. If a candidate receives strictly more than 50% of the votes cast in that round, that candidate is declared the winner of the election. Otherwise, the candidate with the fewest votes in that round is eliminated, and another round is held. If multiple candidates are tied for the least number of votes, they are all eliminated. If all the candidates are eliminated, the election ends without a winner.

            You are given the preferences of the voters in an election, and you must determine the outcome. There are M candidates numbered 0 to M-1, inclusive. The preferences are given in N lines, where each element describes the preferences of a single voter. This is a permutation of the digits 0 to M-1 in decreasing order of preference. In other words, the first digit is the voter's most preferred candidate, the second digit is his second most preferred candidate, and so on.

            Input

            There are several test cases,each test case begins with a integer N(1<=N<=50),means there are N voters.The next N lines,each contains a string with the same lenth M(1<=M<=10).Each element of a voter will be a permutation of the digits between 0 and M-1. There is a blank line between each test case.

            Output

            For each test case,output the number of the candidate who wins the election, or -1 if the election ends without a winner.

            Sample Input

            5
            120
            102
            210
            021
            012

            8
            3120
            3012
            1032
            3120
            2031
            2103
            1230
            1230
             

            Sample Output

            1
            -1


            Hint:
            Case 1:
            Nobody gets an absolute majority in the first round and candidate 2 is eliminated. Candidate 1 then receives 3 votes in the next round, giving an absolute majority.

            Case 2:
            Candidate 0 is eliminated in the first round of voting. Candidate 2 is eliminated in the second round. In the third round, candidates 1 and 3 get 4 votes each. Neither candidate receives an absolute majority, and they are both eliminated for having the least number of votes, so the election ends without a winner.


             

            這題的投票,每輪都是從第一個(gè)數(shù)開始找的,找到第一個(gè)沒有被淘汰的人。
            我一開始以為之前幾輪選的人,在后面不能被選了。。。。

            posted @ 2008-03-31 20:57 chinaeli 閱讀(300) | 評(píng)論 (0)編輯 收藏

            2008年3月27日

            C++第四次作業(yè)(統(tǒng)計(jì))

            #include<iostream>
            #include
            <string>
            #include
            <iomanip>
            #include
            <vector>
            #include
            <algorithm>
            const int MAXN=100;
            using namespace std;
            int cmp ( const void* p1 , const void *p2 )
            {
                return 
            *double* )p1>*(double*)p2?1:-1;
            }
            typedef struct COLOR
            {
                
            string col;
                
            double mean,median,sum,value[MAXN];
                
            int num,p;
            }COL;
            int find ( vector<COL> &str , COL s )
            {
                
            for ( vector<COL>::size_type i = 0; i != str.size(); i++ )
                    
            if ( str[i].col==s.col )
                    {
                        str[i].sum
            +=s.sum;
                        str[i].num
            ++;
                        str[i].value[str[i].p
            ++]=s.sum;
                        return 
            1;
                    }
                return 
            0;
            }
            void add ( vector
            <COL>& str , COL s )
            {
                
            if ( !find ( str , s ) )
                {
                    s.p
            =1;
                    s.num
            =1;
                    s.value[
            0]=s.sum;
                    str.push_back(s);
                }
            }
            void output ( vector
            <COL> str )
            {
                
            double s=0,v[MAXN],median;
                
            int n=0,q,j=0;
                
            for (vector<COL>::size_type i = 0; i != str.size(); ++i )
                {
                    
            for (q=0 ; q<str[i].p ; q++)
                        v[j
            ++]=str[i].value[q];
                    s
            +=str[i].sum;
                    n
            +=str[i].p;
                    qsort(str[i].value,str[i].num,sizeof(str[i].value[
            0]),cmp);
                    
            if (str[i].num%2)
                        str[i].median
            =str[i].value[(str[i].num-1)/2];
                    
            else
                        str[i].median
            =(str[i].value[str[i].num/2]+str[i].value[str[i].num/2-1])/2;
                    cout
            <<str[i].col<<"\t"<<""<<"sum="<<"\t"
                        
            <<setw(10)<<str[i].sum<<"\t"<<"mean="<<"\t"
                        
            <<setw(10)<<str[i].sum/str[i].num<<"\t"<<"median="<<"\t"
                        
            <<setw(10)<<str[i].median<<endl;
                        
                    
            /*
                    
            for ( int j=0 ; j<str[i].p ; j++ )
                        cout
            <<str[i].value[j]<<endl;
                        
            */
                }
                qsort(v,j,sizeof(v[
            0]),cmp);
                
            if (n%2!=0)
                    median
            =v[(n-1)/2];
                
            else
                    median
            =(v[n/2]+v[n/2-1])/2;
                
                cout
            <<"============================================================================"<<endl;
                cout
            <<"ALL"<<"\t"<<""<<"sum="<<"\t"
                    
            <<setw(10)<<s<<"\t"<<"mean="<<"\t"
                    
            <<setw(10)<<s/n<<"\t"<<"median="<<"\t"
                    
            <<setw(10)<<median<<endl;
                
            /*
                
            for ( j=0 ; j<n ;j++ )
                    cout
            <<v[j]<<endl;
                    
            */
            }
            int main ( )
            {
                vector
            <COL> str;
                COL s;
                
            while ( cin>>s.col>>s.sum )
                {
                    add(str,s);
                }
                output( str );
            }

            posted @ 2008-03-27 17:24 chinaeli 閱讀(216) | 評(píng)論 (0)編輯 收藏
            C++第四次上機(jī)作業(yè)(異或加密)


            上面這個(gè)代碼首先通過main函數(shù)的參數(shù)*args[]讀入key,利用(i++)%len實(shí)現(xiàn)對(duì)key各個(gè)字符的循環(huán)操作。利用cin.get( )依次讀入各個(gè)字符,并與key中的字符進(jìn)行異或運(yùn)算,得到加密的字符。由于異或運(yùn)算的可逆性,即 a==(a^b)^b ,可以恢復(fù)得到原文。在調(diào)試過程中發(fā)現(xiàn),加密會(huì)得到一個(gè)ASCII碼編號(hào)為26的字符,然后在解密的時(shí)候,若讀入這個(gè)編碼為26的字符,程序就會(huì)終止。所以第一個(gè)想法就是忽略所有非打印字符,在編碼時(shí),若所得密碼為非打印字符,則不進(jìn)行加密,輸出原文。但是受到了老師的否認(rèn)。于是再作修改,經(jīng)實(shí)驗(yàn)發(fā)現(xiàn),只有編碼為26的字符會(huì)出現(xiàn)這種奇怪的情況,因此決定將這個(gè)字符定義成編碼為27的字符,如’u’^’o’會(huì)產(chǎn)生26的字符,就把這個(gè)字符改成27,結(jié)果最后出現(xiàn)原來應(yīng)該是’o’的,解密得到了’n’,但是沒有其他更好的辦法了,總會(huì)有點(diǎn)誤差的嘛。

            以下為修改后的代碼
            #include<iostream>
            #include
            <cstring>
            using namespace std;
            const int MAXN=100000;
            int main ( int argc , char *args[] )
            {
                char p,code;
                
            int i=0,l;
                char key[MAXN];
                
            if ( argc<2 )
                    
            while ( cin.get(p)   )
                        cout.put(p);
                
            else
                {
                    strcpy(key,args[
            1]);
                    l
            =strlen(key);
                    
            while ( cin.get(p)  )
                    {
                        code
            =p^key[i%l];
                        
            if ( code==26 )
                            code
            =27;
                        cout
            <<code;
                        i
            ++;
                    }
                }    
            }

            posted @ 2008-03-27 12:35 chinaeli 閱讀(1385) | 評(píng)論 (0)編輯 收藏
            詳細(xì)解說 STL 排序(Sort)

                 摘要: 0 前言: STL,為什么你必須掌握 對(duì)于程序員來說,數(shù)據(jù)結(jié)構(gòu)是必修的一門課。從查找到排序,從鏈表到二叉樹,幾乎所有的算法和原理都需要理解,理解不了也要死記硬背下來。幸運(yùn)的是這些理論都已經(jīng)比較成熟,算法也基本固定下來,不需要你再去花費(fèi)心思去考慮其算法原理,也不用再去驗(yàn)證其準(zhǔn)確性。不過,等你開始應(yīng)用計(jì)算機(jī)語(yǔ)言來工作的時(shí)候,你會(huì)發(fā)現(xiàn),面對(duì)不同的需求你需要一次又一次去用代碼重復(fù)實(shí)現(xiàn)這些已經(jīng)成熟的...  閱讀全文

            posted @ 2008-03-27 02:57 chinaeli 閱讀(296) | 評(píng)論 (0)編輯 收藏
            我可憐的第三次C++作業(yè)啊~~~只有70分~~~

             助教給我的郵件中這樣說:

            Jerry Huang  致 我
             顯示詳細(xì)信息  3月21日 (6天前) 

            Hi,

            我編譯了你們的代碼,進(jìn)行了測(cè)試,好像和希望的結(jié)果差距比較大,請(qǐng)你們?cè)贆z查確認(rèn)一下。

            如果是提交錯(cuò)了,請(qǐng)重新提交。

            Thanks

            huang

            結(jié)果我只打了70分。。。。。

             1#include<iostream>
             2using namespace std;
             3/* 判斷字符串是否在引號(hào)里面 */
             4int qutation ( char c , bool &f ,bool f1 )
             5{
             6    char temp;
             7    if ( c=='"' && f1==false)
             8    {
             9        f=true;
            10        cout<<c;
            11        while ( f==true )
            12        {
            13            cin.get(temp);
            14            if ( temp=='"')
            15                f=false;
            16            cout<<temp;
            17        }
            18        return 1//發(fā)現(xiàn)引號(hào)
            19    }
            20    return 0//沒有發(fā)現(xiàn)引號(hào)
            21}
            22void cut_add  ( )
            23{
            24    char c,temp;
            25    bool f1,f2,f3;
            26    f1=f2=f3=false// f1標(biāo)記block注釋,f2標(biāo)記引號(hào),f3標(biāo)記line注釋
            27    while ( cin.get(c) )
            28    {
            29        if ( !qutation(c,f2,f1) )  // 沒有出現(xiàn)引號(hào)
            30        {    
            31            /*判斷注釋開頭*/
            32            if ( c=='/' )
            33            {
            34                cin.get(temp);
            35                if ( temp=='*' )
            36                    f1=true;//找到了block注釋的開頭
            37                else
            38                    if ( temp=='/' )
            39                        f3=true;//找到了line注釋的開頭
            40                /*當(dāng)沒有找到注釋的開頭時(shí),執(zhí)行else部分*/
            41                    else
            42                    {
            43                        cout<<c;            
            44                        cin.putback(temp);
            45                    }
            46            }
            47            else
            48                if ( f1==false && f3==false )
            49                    cout<<c;
            50            /*判斷注釋結(jié)尾*/
            51            if ( c=='*' )
            52            {
            53                cin.get(temp);
            54                if ( temp=='/' )
            55                    f1=false//關(guān)閉block注釋
            56                else
            57                {
            58                    cout<<c;
            59                    cin.putback(temp);
            60                }
            61            }
            62            else
            63                if ( c=='\n' )
            64                {
            65                    f3=false//關(guān)閉line注釋
            66                    cout<<c;
            67                }
            68        }    
            69    }
            70}
            71int main ( )
            72{
            73    cut_add();
            74}

            我不知道什么原因,手動(dòng)輸入可以的,但是用文件輸入輸出的話,輸出就停不了了。。。。


            題目:
            就是給你個(gè).cpp文件,這是加注釋的,然后讓你生成一個(gè).txt文件,除去代碼的注釋。
            用命令行輸入:
            erasecomment < DataIn.cpp  > result.txt

            posted @ 2008-03-27 01:06 chinaeli 閱讀(297) | 評(píng)論 (1)編輯 收藏
            僅列出標(biāo)題  
            久久精品国产99国产电影网| 国产午夜福利精品久久| 青青草原综合久久| 国内精品久久国产| 欧美综合天天夜夜久久| 精品久久久无码人妻中文字幕| 亚洲天堂久久精品| 久久久无码精品亚洲日韩蜜臀浪潮| 久久一区二区三区99| 久久国产亚洲高清观看| 国产成人综合久久精品红| 国产午夜福利精品久久| 久久99精品国产99久久6男男| 久久99热这里只有精品国产| 久久久99精品成人片中文字幕| 韩国免费A级毛片久久| 久久久久久久久久久久久久| 久久精品成人一区二区三区| 久久免费线看线看| A狠狠久久蜜臀婷色中文网| 亚洲国产另类久久久精品小说| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久国产精品久久| 奇米影视7777久久精品| 亚洲国产精品一区二区久久hs| 久久99国产精品久久99小说| 久久一本综合| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 欧美亚洲国产精品久久高清| 久久久精品国产Sm最大网站| 99久久国产综合精品成人影院| 久久青草国产手机看片福利盒子 | 婷婷伊人久久大香线蕉AV | 国产精品久久久久影视不卡| 青草国产精品久久久久久| 亚洲国产另类久久久精品| 久久亚洲日韩精品一区二区三区| 久久久久久无码Av成人影院| 久久中文字幕视频、最近更新 | www久久久天天com| 久久99热这里只有精品国产|