(hdu2612)

鬱悶死:很容易理解的題,第一次果斷逾時;借第一次的經驗;在搜尋到兩個人的過程也把到他們之間的距離存了起來;結果錯誤,和學哥找了一晚上,嚓,原來錯著了,乖乖,字串還沒輸出完我就開始尋找了。。不過經過這次找錯,錯一點,什麼不可思議的結果都會出來。。#include"stdio.h"#include"string.h"#include"queue"#define inf 99999char map[300][300];int visit[300][300];int

hdu(2616)Kill the monster

 /*對於這種情況很多,很難分析的題;一般用搜尋,用回朔搜尋,搜盡所有可能,然後取出最優解;*/#include"stdio.h"#define inf 9999999int a[20],b[20];int n,m,min,visit[20];void bfs(int v,int w){ int i; if(v<=0) {  if(min>w)   min=w; } for(i=1;i<=n;i++) {  if(visit[i]==0)  {   visit[i]=1;   

UVa 567: Risk

這是一道很簡單的圖論題,只要使用寬度優先搜尋(BFS)標記節點間距離即可。我的解題代碼如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <string>#include <algorithm>#include <queue>using

poj 3411 Paid Roads

這題很特別,因為標記不能簡單的為一次,他有可能為多次。。但又不能不標記,不然無法結束。。 大致題意:有n座城市和m(1<=n,m<=10)條路。現在要從城市1到城市n。有些路是要收費的,從a城市到b城市,如果之前到過c城市,那麼只要付P的錢,如果沒有去過就付R的錢。求的是最少要花多少錢。注意:路徑是有向的。這題痛點在於“城市與城市之間可能存在多條路徑”:1、  輸入資料時可能會出現多條 從城市a到城市b的路徑資訊,但是費用有所差別;2、  對於 從城市a到城市b

UVa 253: Cube painting

這道題要我們判斷對於一個立方體用三種顏色染色(可以只使用其中的一種或兩種顏色),題目所給的兩種染色方案本質上是否相同(即立方體經過翻轉後可重合)。對於這道題,我們只要枚舉出第一種染色方案下的立方體所有能夠通過翻轉產生的其他本質相同的染色方案,與第二種方案比較就可以得到結果。即枚舉立方體繞X,Y,Z軸旋轉後的結果(三個軸均可以繞著旋轉0度,90度,180度,270度),最多4^3=64中情況。我的解題代碼如下:#include <iostream>#include

UVa 10161: Ant on a Chessboard

很簡單的一題找規律題。我的解題代碼如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <string>#include <algorithm>using namespace std;int main(){int N;while(cin >> N &

UVa 621: Secret Research

簡單題,不解釋。My Code如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <string>#include <algorithm>using namespace std;char s[1000];int main(){int T;cin >> T;

hdu(1596)

用floyd求最大值。 #include"stdio.h"#include"string.h" double map[1010][1010];#define max(a,b) a>b?a:b貌似這樣省時些,不然會逾時。。int main(){ int

hdu(1269)迷宮城堡

題意很容易理解;;//強連通是任意兩點都能到達,雙向的。#include"stdio.h"int pre[100001];int find(int k){if(k!=pre[k])pre[k]=find(pre[k]);return pre[k];}int main(){int

hdu(4323)HDU 4323 Magic Number 編輯距離(經典DP)

下面是關於編輯距離的有關介紹;  一,字串A到B的編輯距離是指,只用插入、刪除和替換三種操作,最少需要多少步可以把A變成B。二,首先,我們觀察Levenshtein距離的性質。令d(x,y)表示字串x到y的Levenshtein距離,那麼顯然:      1. d(x,y) = 0 若且唯若 x=y  (Levenshtein距離為0 <==> 字串相等)      2. d(x,y) = d(y,x)     (從x變到y的最少步數就是從y變到x的最少步數)      3.

編輯距離 字串相似性問題

編輯距離        關於兩個字串s1,s2的差別,可以通過計算他們的最小編輯距離來決定。        所謂的編輯距離: 讓s1和s2變成相同字串需要下面操作的最小次數。 1.     把某個字元ch1變成ch2 2. 刪除某個字元 3. 插入某個字元 例如 s1 = “12433” 和s2=”1233”; 則可以通過在s2中間插入4得到12433與s1一致。    即 d(s1,s2) = 1 (進行了一次插入操作) 編輯距離的性質 計算兩個字串s1+ch1,

hdu(2579) Dating with girls(2)

這個題有意思的是:牆可以消失,只要時間是k的倍數,在此時牆都可以消失一秒,單此題不同之處就是,每一個點可以走多次,但必須是在不同的時刻,這就必須要用三維數組來標記了。visit[i][j][s/k]表示在(i,j)這個點在s/k的時刻走過了。。所以在本題可以行走的條件是;一;map[i][j]=='.';二;map[i][j]=='#'and s/k==0時;任意一個都行。。 #include"stdio.h"#include"string.h"#include"queue"int visit[

(hdu)1035 Robot Motion

/*為了計算迴圈時的步數,用visit來及所走每一個點的步數;同時,他也其標記的作用。。*/  #include"stdio.h"#include"string.h"char map[100][100];int visit[100][100];int n,m,step;int judge(int x,int y){ if(x>=0&&x<n&&y>=0&&y<m)  return 1; return 0;}int

hdu(1276)士兵隊列訓練問題

題意很清楚,但要注意一點,就是判斷for迴圈結束的條件是:就在在這一輪報完之後,m==3,即可結束。。 #include"stdio.h"#include"string.h"int main(){ int n,m,k,i,s,t;    int a[6000]; scanf("%d",&k); while(k--) {  scanf("%d",&n);  for(i=1;i<=n;i++)   a[i]=1;      m=n;  while(m>3)  {    

hdu (2578) Dating with girls(1)

此題應注意的是;這n個數可能有相同的,所以把相同的留一個在這裡,#include<stdio.h>#include<stdlib.h>int cmp(const void*a,const void*b){    return *(int*)a-*(int*)b;}int main(){    int m,n,i,j,k,h,low,hig,mid,p;    int a[100005],b[100005];    scanf("%d",&m);    while(

(hdu) 1258 Sum It Up

此題重點在於要防止重複計算,引入temp,記錄上一個,只要下一個數與他不相等即可。。這裡也是用回朔搜尋,來找完所有可能。。#include"stdio.h"#include"string.h"int visit[100];int a[100],b[100];int n,m,flag;void bfs(int x,int sum,int k){ int

UVa 10025: The ? 1 ? 2 ? … ? n = k problem

這道題仔細思考後就可以得到比較快捷的解法,只要求出滿足n*(n+1)/2 >= |k| ,且n*(n+1)/2-k為偶數的n就可以了。注意n==0時需要特殊判斷。我的解題代碼如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <string>#include

(hdu)1027 全排序

調用STL庫函數next_permutation(startAddress,endAddress)  #include"stdio.h"#include"algorithm"using namespace std;int main(){ int n,m,i; int a[20000]; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++) a[i]=i+1;

UVa 10048: Audiophobia

這道題要求我們求出圖中的給定的兩個節點(一個起點一個終點,但這是無向圖)之間所有“路徑中最大權值”的最小值,這無疑是動態規劃。我開始時想到根據起點和終點用動態規劃直接求結果,但最終由於題中S過大,會逾時。逾時的代碼如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include

UVa 11748: Rigging Elections

先附上題目如下:Elections in your country are performed in a one-on-one elimination style. Each week, two people are chosen from a pool of candidates and the country votes on which one they prefer. The loser is eliminated and the winner is returned to the

總頁數: 61357 1 .... 14319 14320 14321 14322 14323 .... 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.