Time of Update: 2018-12-03
曾經寫過一遍,不過這次似乎寫得更加順暢。注意10^5,是多大……我竟然把MAX_SIZE定義小了一個數量級==!/* * find them, catch them * mike-w * 2012-4-28 */#include<stdio.h>#include<stdlib.h>#include<string.h>#define MAX_SIZE 123456int T,N,M;int diff[MAX_SIZE];int
Time of Update: 2018-12-03
為什麼把這個題分到DP的分類中!!!做完本題的感想:1.仔細讀題2.注意資料的格式/* * POJ-1125 stockbroker grapevine * mike-w * 2011-10-23 * ------------------------------ * Note that the time taken to pass the message from person A to person B * is not necessarily the same as the time
Time of Update: 2018-12-03
#include<cstdio>#include<cstring>#define MAXN 200struct stack{ int top,node[MAXN];}s;int Edge[MAXN][MAXN];int n;void dfs(int x){ int i; s.top ++; s.node [s.top
Time of Update: 2018-12-03
hdu2110Crisis of HDU0<pi,mi<10 這個條件貌似不對,用p[i] m[i]分別儲存才過(之前是模板的方法)#include<iostream>using namespace std;int c1[4000],c2[4000],X[101],P[101];int main(){int T,n,m,k,a,b,i,j,num,sum;while(scanf("%d",&n),n){memset(X,0,sizeof(X));for(sum=0
Time of Update: 2018-12-03
我對二分圖匹配有了新理解,二分圖的精華在於“二分”這兩個字——整個圖可以被分成兩部分,我們在進行匹配的時候是在分清了二分圖的兩部分後才進行的,就是說:對於一個結點,我們在二分圖匹配的時候已經知道了它的位置,即左邊的半個圖或者右邊的半個圖。此題應是模板題。/*ID: creativ3TASK: stall4LANG: C*//* * USACO: the perfect stall * mike-w * 2011-10-21 * 二分圖匹配 * ps: 剛才我犯了一個愚蠢的錯誤!
Time of Update: 2018-12-03
#include<stdio.h>#include<string.h>struct node{int a,b,value;}tree[300005];int ans;void maketree(int i,int a,int b){tree[i].a=a;tree[i].b=b;tree[i].value =1;if(a==b)return;int mid=(a+b)/2;maketree(i*2,a,mid);maketree(i*2+1,mid+1,b);}void
Time of Update: 2018-12-03
砝碼稱重 設有 1g 、 2g 、 3g 、 5g 、 10g 、 20g 的砝碼各若干枚(其總重 <=1000 ), 要求: 輸入方式: a1 a2 a3 a4 a5 a6 (表示 1g 砝碼有 a1 個, 2g 砝碼有 a2 個,…, 20g 砝碼有 a6 個) 輸出方式: Total=N ( N 表示用這些砝碼能稱出的不同重量的個數,但不包括一個砝碼也不用的情況) 如輸入: 1_1_0_0_0_0
Time of Update: 2018-12-03
#include<stdio.h>#include<math.h>int num[25];int n;int judge(){int i,k;k=num[1];for(i=2;i<=n;i++){ if(num[i]!=k)break;}if(i<=n)return true;elsereturn false;}int main(){int i,j,k; int h=0;while(1){scanf("%d",&n);h++;if(
Time of Update: 2018-12-03
hdu2069錯解//忽略了所有硬幣總數小於100的限制,導致方案數偏大 #include<iostream>using namespace std;int main(){int
Time of Update: 2018-12-03
又複習了一遍逆序對數的求法。一個愚蠢的BUG調試了很長時間——printf()寫到大括弧外面了,結果...#include<stdio.h>#include<stdlib.h>#include<string.h>#define lowbit(x) ((x)&(-(x)))#define max_n 1010101typedef struct _node{int num,id;}node;int seq[max_n];node
Time of Update: 2018-12-03
#include<iostream>using namespace std;int X[18],c1[301],c2[301];int main(){int i,j,num,sum;for(i=1;i<=17;i++)X[i]=500;//printf("!!!!!!!!\n");while(scanf("%d",&sum),sum){memset(c1,0,sizeof(c1));memset(c2,0,sizeof(c2));for(i=0;i<=300;i+
Time of Update: 2018-12-03
回溯回溯回溯回溯回溯回溯回溯hdu1010#include<stdio.h>#include<string.h>int abs(int x){return x<0? -1*x:x;}int m,n,T,mp[10][10],Sx,Sy,Dx,Dy,flag,dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};void dfs(int x,int y,int t){int i,temp;if(x==Dx&&y==Dy&&
Time of Update: 2018-12-03
更正了自己對多重背包的錯誤處理方法——有收穫!在把多重背包劃歸成0-1背包時要注意劃分方法。/* * HDU-1058 dividing * mike-w * 2011-10-5 * ----------------- * 多重背包 * 原來我對多重背包的處理一直有誤, 今日才發現! */#include<stdio.h>#include<stdlib.h>#include<string.h>#include<assert.h>#define
Time of Update: 2018-12-03
hdu1028好像母函數的題目都挺簡單的,寫了幾個都是模板另外還有動態規劃的方法#include<iostream>using namespace std;int main(){int X[121],c1[121],c2[121],N,i,j,num;for(i=1;i<=120;i++)X[i]=120;while(scanf("%d",&N)!=EOF){memset(c1,0,sizeof(c1));memset(c2,0,sizeof(c2));for(i=0;
Time of Update: 2018-12-03
hud1342dfs第二題 不怎麼熟練看了別人的代碼//hdu 1342 poj2245#include<iostream>#include<stdio.h>using namespace std;int ans[6],S[20];void dfs(int k,int next,int n){int i,j;if(n==7){for(i=1;i<=6;i++){if(i==1)printf("%d",ans[i]);else printf(" %d",ans[i]
Time of Update: 2018-12-03
#include<stdio.h>#include<string.h>struct node{ int a,b,value;}tree[600005];int k;int max(int a,int b){ return a>b?a:b;}void maketree(int i,int a,int b){ if(a==b) { tree[i].a=a; tree[i].b=b;
Time of Update: 2018-12-03
hdu2152從給出的N種水果中選出限制範圍最大M種然後母函數#include <iostream>#include<algorithm>using namespace std; int N, M;//int A, B;struct fruit{int A,B;}X[101];int a[105], b[105];int c1[105], c2[105];bool cmp(fruit a,fruit b){return
Time of Update: 2018-12-03
#include<stdio.h>#include<string.h>struct node{ int a,b,value;}p[2005];int min(int a,int b){ return a<b?a:b;}int main(){ int c,i,j,k,n,m,d; int dp[2005]; scanf("%d",&c); for(i=1;i<=c;i++) { scanf("%d%d",&n,&m);
Time of Update: 2018-12-03
最大連續子串hdu1003最普通的版本dp[i]=max{ dp[i-1]+dat[i] , dat[i] }對於當前的數字dat[i], 有兩種選擇A.原子串增長,dp[i]=dp[i-1]+dat[i]~~~~~前提是dat[i]<=dp[i-1]+dat[i]B.原子串結束,以dat[i]為起點開始新子串。~~~~~前提是dat[i]>dp[i-1]+dat[i]註:以原子串的長度來劃分有三種情況。1.增長 對應上文選擇中的A2.不變
Time of Update: 2018-12-03
調試了一會,發現程式沒錯,測試資料錯了——讀入的還是上一題的資料==||||還是那句老話——“同學,要細心!”簡單BFS。/* * tyvj-1074 武士風度的牛 * mike-w * 2011-10-26 * --------------------- * BFS */#include<stdio.h>#include<stdlib.h>#include<string.h>#define SIZE 155#define QSIZE