Time of Update: 2018-12-05
HDU-1028-Ignatius and the Princess IIIhttp://acm.hdu.edu.cn/showproblem.php?pid=1028整數劃分,無奈,逾時#include<stdio.h>int huafen(int n,int m)//將n分為最大加數不超過m{if(n<1||m<1)return 0;if(n==1||m==1)return 1;if(n<m)return huafen(n,n);if(n==m)return
Time of Update: 2018-12-05
POJ-2739-Sum of Consecutive Prime Numbershttp://poj.org/problem?id=2739判斷一個數能由多少種連續的素數構成,數目不大,先打表求出範圍內的所有素數#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 10005char a[N];int b[N];int main(){int
Time of Update: 2018-12-05
#include<iostream>#include<cstdio>#include<queue>using namespace std;typedef struct Point{ int x, y;}POINT;queue <POINT> me;POINT Begin , End;bool visited[9][9];bool flag;int ans;int movei[8]= {2,-2,1,-1,2,-2,1,-1};int
Time of Update: 2018-12-05
POJ -3126-Prime Pathhttp://poj.org/problem?id=3126素數打表加BFS#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<queue>using namespace std;#define N 10005int prime[10005];int visit[N];struct
Time of Update: 2018-12-05
HDU-1698-Just a Hookhttp://acm.hdu.edu.cn/showproblem.php?pid=1698還是成段更新線段樹#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 100005struct cam{int x;int y;int sum;int val;}list[N*4];void build(int k,int x,int y){int mid;
Time of Update: 2018-12-05
HDU-3371-Connect the Citieshttp://acm.hdu.edu.cn/showproblem.php?pid=3371最小產生樹,已知有些節點已經相連#include<stdio.h>#include<string.h>#include<stdlib.h>struct cam{int x;int y;int len;}list[25005*3];int f[505];int n,m,k;int find(int x){int
Time of Update: 2018-12-05
HDU-3074-Multiply gamehttp://acm.hdu.edu.cn/showproblem.php?pid=3074求區間元素的乘積,可以更新元素,線段樹即可#include<stdio.h>#include<string.h>#include<stdlib.h>#define Mod 1000000007#define N 50005int num[N];struct cam{int x; //起點int y; //終點__int64
Time of Update: 2018-12-05
HDU-1596-find the safest roadhttp://acm.hdu.edu.cn/showproblem.php?pid=1596SPFA演算法#include<iostream>#include<cstdio>#include<cstring>using namespace std;int n,m,st,ed,front,rear;double mat[1005][1005],dis[1005];int v[1005],q[1000001
Time of Update: 2018-12-05
HDU-1372-Knight Moveshttp://acm.hdu.edu.cn/showproblem.php?pid=1372求“馬”從一點到另一點的最短距離,馬走日,BFS即可#include<stdio.h>#include<string.h>#include<stdlib.h>int dir[8][2]={{-2,1},{-2,-1},{2,-1},{2,1},{-1,2},{-1,-2},{1,2},{1,-2}};int ans[10][10
Time of Update: 2018-12-05
HDU-1166-敵兵布陣http://acm.hdu.edu.cn/showproblem.php?pid=1166求區間的和,並可更新,線段樹#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 50005int num[N];struct cam{int x; //起點int y; //終點int sum; //總數}list[N*4];void build(int k,int
Time of Update: 2018-12-05
HDU-1010-Tempter of the Bonehttp://acm.hdu.edu.cn/showproblem.php?pid=1010給這題折騰了半天啊,剛開始用BFS寫的,總是WA,後來發現這題要求在給定的時間點到達,不能早,也不能遲,而BFS每次求出的是最短時間,不合題意,於是轉用DFS,剪枝的方法是參考HDU的PPT寫的,居然還要考慮奇偶性可以把map看成這樣: 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0
Time of Update: 2018-12-05
HDU-4068-SanguoSHAhttp://acm.hdu.edu.cn/showproblem.php?pid=4068字串類比,枚舉自己和對手的牌的全排列即可#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int map[10][10];char str[10][25];int
Time of Update: 2018-12-05
HDU-1754-I Hate Ithttp://acm.hdu.edu.cn/showproblem.php?pid=1754查詢區間的最大值,並可以更新線段樹即可,為區間[1,5]的線段樹#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 200005int num[N];struct cam{int x; //起點int y; //終點int max;
Time of Update: 2018-12-05
HDU-4325-Flowershttp://acm.hdu.edu.cn/showproblem.php?pid=4325成段更新加離散化線段樹這題做了快有一天了。。。。各種問題啊,開始建樹時沒有把查詢的節點加入樹中,結果在查詢時發現很多節點的資訊丟失了,糾結了半天去看了下別人的代碼,原來建樹時就應把查詢的節點加入,在做離散化時,將hash數組開到10^9,又超記憶體了,通不過編譯,囧,之後改成map映射,終於羞愧的A了(這題的資料可能比較弱,不加離散化也能過)#include<iost
Time of Update: 2018-12-05
HDU-1244-Oil Depositshttp://acm.hdu.edu.cn/showproblem.php?pid=1241基本的DFS#include<stdio.h>#include<string.h>#include<stdlib.h>char map[105][105];int n,m;int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};int
Time of Update: 2018-12-05
HDU-1305-Immediate Decodabilityhttp://acm.hdu.edu.cn/showproblem.php?pid=1305字典樹水題,判斷首碼#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;struct node{int count;node *childs[2];node(){count=
Time of Update: 2018-12-05
HDU-3790-最短路徑問題http://acm.hdu.edu.cn/showproblem.php?pid=3790單源最短路勁,更新路勁時要更新花費#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;#define INF 0x7fffffffint n,m;int map[1005][1005];int cost[1
Time of Update: 2018-12-05
POJ-1321-棋盤問題http://poj.org/problem?id=1321基本的DFS#include<stdio.h>#include<string.h>#include<stdlib.h>int n,t,ans;char map[10][10];int visit[10];void dfs(int x,int y){int i;if(y==t){ans++;return;}if(x>=n)return;
Time of Update: 2018-12-05
HDU-2795-Billboardhttp://acm.hdu.edu.cn/showproblem.php?pid=2795線段樹,建樹時要注意範圍#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;#define N 200005int h,w;struct cam{int x;int y;int
Time of Update: 2018-12-05
HDU-2612-Find a wayhttp://acm.hdu.edu.cn/showproblem.php?pid=2612求2個點到KFC的距離之和,使其最小,可用2次BFS,分別求出2個點到各個KFC的最短距離,然後找出和最小的即可#include<stdio.h>#include<string.h>#include<stdlib.h>#define max 0x7fffffffint n,m;char map[250][250];int