poj1472 類比計算複雜度

        題不難,但是很噁心。輸出格式也很極品,尤其我還犯了個不起眼的錯,找了好久。就是寫出了下面非常捉急的兩行代碼:int *coff=(int*)malloc(11*sizeof(int));memset(coff,0,sizeof(coff));發現程式時對時錯,通過各種列印語句........發現錯在memset這行,但是還是沒發現有啥不對。上了趟廁所才想起來這地方不是靜態數組了,以前初始化數組寫習慣了,真是智商捉急啊........改成這樣就好了:int *coff=(int*)

poj2251 Dungeon Master(BFS)

        三維的迷宮找最短路,當然是寬搜了。不好估計隊列會膨脹到多大時,用鏈表好些.....#include <stdio.h>#include <stdlib.h> #include <string.h>typedef struct tPoint{int level;int row;int col;int steps;//步數struct tPoint* next;}Point;int L;int R;int C;char ch[30][30][31]

poj2499 Binary Tree

        說白了就是輾轉相除。#include <stdio.h>int left;int right;void to_root(int a,int b){//如果a>b,說明該節點是其父的左孩子,反之右孩子if(a==1){right+=(b-a);return;}if(b==1){left+=(a-b);return;

poj1050 最大子矩陣和

        可以歸結為一維數組最大子序列和的問題,關鍵就是要利用一維數組最大子序列和的O(n)解法。#include <stdio.h>#include <stdlib.h>int a[100][100];int col_sum[100][100][100];int N;int to_max(int start_row,int end_row){//一維數組的最大子序列和int max=-127*100*100;int sum=0;int

poj1221 UNIMODAL PALINDROMIC DECOMPOSITIONS (dp)

       

poj1002 電話號碼

        這個題做法應該也不少。考慮到這裡的電話號碼最大是999-9999,因此我選了個省腦子的放法,開了個10000000的數組.........因此剩下的工作就是把輸入的字串轉化成integer ,注意好英文字母和數字間的對應,然後就是個簡單的atoi了。#include <stdio.h>#include <string.h>int count[10000000];int alpha_to_digit[]={2,2,2,3,3,3,4,4,4,5,5,5,6,

poj1029 False coin

        又是稱硬幣,三種考慮:1如果天平平衡,那天平上的都是正常的。2如果不平衡,那麼不在天平上的都是正常的;另外如果一個硬幣在某次稱重時出現在了較輕的一端,某次稱重時又出現在了較重的一端,那麼它也是正常的。#include <stdio.h>#include <string.h>int N,pi;int coin[1001];int left[501];int right[501];int left_o[1001];int right_o[1001];void

poj1125 股票訊息傳遞(floyd)

        幾乎是裸的floyd,運行完floyd之後需要順便判斷是否連通。#include <stdio.h>#include <string.h>int N;int d[101][101];void floyd(void){int

poj 3080 kmp水題

題意:找出所有匹配串中的最長公用子串,長度須大於3資料小,從長度為大到小枚舉吧#include<stdio.h>#include<string.h>#define val 65int next[val],tot;char p[val],s[11][val];char ans[val];bool kmp(char *,char *);int main(){int cas,i,j,k,n;bool found;for(scanf("%d",&cas);cas;cas-

第二個BFs HDU1242

這個題好糾結,通過C++提交無限次RE,可是用g++提交一次就AC了,怎麼這些極品問題都是在我身上發生,無語了,上次是系統錯誤,這次是編譯器漏洞。。。。。。#include<stdio.h>#include<string.h>#define Maxsize 10000typedef struct {int x;int y;}position;typedef struct{int tail,head;position a[Maxsize];}queue;void

poj1027 The Same Game

        題意是每次消去最大的可以消去的小球的集合,然後將小球做相應的下沉或者左移的操作,繼續重複上述步驟,直到遊戲結束。很有意思的題目,做這種題目就好像自己在玩這個遊戲.......找最大的集合用寬搜或深搜都行吧,消去後的操作也是要注意好下標。#include <stdio.h>#include <string.h>int N;char a[10][16];int left;int score;int visited[10][15];int direction[4

poj1936 判斷子序列

        題目大意是給兩個串s和t,判斷s是不是t的子序列(這個子序列和LCS中子序列的概念是一樣的,即s中的字元只要按順序在t中出現就好了,不一定是連續出現的)。       

poj2021 Relative Relatives

        可以用寬搜從Ted開始逐步往外擴充,但好像用遞迴的方法更簡潔些。主要就是下面的這個函數了:/**計算i的年齡,有點dp的意思,如果i年齡是-1,那麼先遞迴計算其父親的年齡。*/int calculate_age(int i){if(d[i].age!=-1){return d[i].age;}d[i].age=calculate_age(d[i].parent)-d[i].cost;return d[i].age;}        這個函數是要計算i節點的年齡,如果i的年齡不是-

poj1042 Gone Fishing (dp)

        一開始寫的三維的,dp[l][t][st]代表從l湖開始,總共有t時間能釣到的魚的最大數量,st代表的是已經在這個湖待的時間(因為魚是隨著時間不斷減少的),這樣算來應該是25*192*192,提交逾時了。以為是因為某種情況沒考慮到導致死迴圈了(以前逾時經常是這個原因),就找了不少資料,把官方資料拿過來跑了個遍,結果都對,還是逾時,那確實應該就是三維太大了。。。       

poj3278 Catch That Cow(BFS)

        題意:給兩個數N和K,每次能對N做三種操作中的一種,N=N+1,N=N-1或N=2*N,求要由N變換到K最少需要多少次這樣的操作。還是寬搜......#include <stdio.h>#include <stdlib.h> #include <string.h>typedef struct tPoint{int x;int steps;struct tPoint* next;}Point;int visited[100001];Point*

poj1250 (簡單類比)

#include <stdio.h>#include <string.h>int N;int used;int inbed[26];char str[55];int result;int main(void){while(1){scanf("%d",&N);if(N==0){break;}scanf("%s",str);used=0;memset(inbed,0,sizeof(inbed));result=0;int i=0;int j;char c;while(

poj2366 Sacrament of the sum

        一個升序數組A,一個降序數組B,給一個sum,問是否存在i和j,使sum=A[i]+B[j]。可以考慮用hash,將Ahash之後,遍曆B,尋找sum-B[j]。這裡我用的是另一種方法。        初始化i和j為0,那麼此時A[i]是A中最小的元素,B[j]是B中最大的元素,計算t=A[i]+B[j],如果t==sum,那麼找到結果了。如果t>sum,說明B[j]太大了,因為用A中能用的最小的元素它相加,結果都超過了sum,那麼A中剩下的其他元素和B[j]相加就更大了,

poj3752 字母旋轉

#include <stdio.h>#include <string.h>int M,N;char ch[64][64];int visited[64][64];int directions[4][2]={{0,1},{0,-1},{1,0},{-1,0}};int main(void){scanf("%d %d",&M,&N);memset(visited,0,sizeof(visited));if(M==1&&N==1){printf(

尋找二叉樹某節點的路徑

#include<stdio.h>#include<stdlib.h>typedef struct btree {int data;struct btree *left;struct btree *right;}tree;void preorder(tree *t);void insert(int k,tree *&t);int findpath(int k,tree *t);int main(){int n,k,i;tree *t=NULL;scanf("%d"

poj2503 Babelfish (hash)

        也是簡單的hash,找個好點的hash函數還是挺關鍵的。。。其他的就是簡單的插入尋找什麼的,線性開型解決衝突什麼的#include <stdio.h>#include <string.h>#include <stdlib.h>#define N 100000typedef struct tNode{char f[11];char e[11];struct tNode* next;}Node;Node* node[N];unsigned int

總頁數: 61357 1 .... 21020 21021 21022 21023 21024 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.