UVa 10054(歐拉迴路)

這裡普及一下歐拉迴路的知識。歐拉道路是指的任意一個點開始遍曆,每條邊恰好經過一次,這樣的道路就是歐拉道路。如果能從任意一個點出發,並回到這個點,每條邊恰好經過一次,這樣的道路是歐拉迴路。歐拉道路的判定:在無向圖中,最多隻有度數為奇數的點,則一定存在歐拉道路,並且要從一個奇點出發,到另一個奇點結束;如果全部都是偶數度數的點,那麼就一定存在歐拉迴路。對於有向圖,最多有兩個點的入度不等於出度,其中的一個點的入度必須比出度大1,這個點作為終點,另個一點一定要出度比入度大1,作為起點;如果不存在出度和入度

UVa 657 The die is cast(DFS)

雙層DFS, X數量絕對不超過6個,所以毫無疑問,雙層就可以解決掉!#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int N = 55;int n, m, numx, cnt, ans[N*N];int a[] = { 0, 0, 1, -1 };int b[] = { 1, -1, 0, 0 }

UVa 10596 Morning Walk ( 歐拉迴路 )

有一段時間不寫並查集了,結果寫的時候手生,寫錯了!老大給了這道題, 我開始以為老大給的應該是搜尋的題目,分析了一下,搜尋是可以做的,但是搜的過程比較麻煩,後來看到了 a single walk,看來就是一筆換的問題的,需要回到home,連回家的過程都不能走原來的路,所以是迴路!我看了好幾遍題目,才讀得徹底,它其實是個無向圖的歐拉迴路!說一點體外話,與題目關係不大,我覺得ACM最重要的,除了學習各種演算法以外,還有就是分析問題,找到問題的最本質,然後解決問題!所以說,分析問題的能力是非常重要的……

uva 10167 Birthday Cake

         暴力這一章的基礎,枚舉的題目。#include<cstdio>using namespace std;typedef struct Point{ int x,y;}Point;int main(){ int n,a,b,numofp,num1,num2; Point point[100]; while(scanf("%d",&n)!=EOF&&n) { numofp=0;

codeforces 289 B. Polo the Penguin and Matrix

題目連結題目意思是在n*m的矩陣中,你可以對矩陣中的每個數加或者減d,求最少的操作次數,使得矩陣中所有的元素相同。雖然在condeforces中被分到了dp一類,但完全可以通過排序,暴力的方法解決。#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;const int maxn = 10005;int

codeforces 304A. Pythagorean Theorem II

題目連結給你一個n,計算出1 ≤ a ≤ b ≤ c ≤ n.使得由abc構成的三角形滿足勾股定理,c為斜邊。沒有簡單的方法,直接爆力,但是要注意,有些abc滿足勾股定理的運算式,但不一定是三角形,所以要判斷一下,根據三角形三邊的性質,兩邊之和大於第三邊,兩邊之差小於第三邊。//cf304 A//2013-06-05-18.14#include <stdio.h>#include <math.h>int main(){ int n; while (scanf(

uva 10282 Trie樹

 字典樹是雜湊樹的一種,通常用於字串匹配,由于思想和實現都很簡單,所以我就不再介紹了,自己google之吧。。很水的題,RE了一次,好吧我現在太浮躁了...#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>#define CLR(array,val)

UVa 572 Oil Deposit (DFS)

so easy!#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int N = 110;int n, m, ans;char g[N][N];int a[] = { 0, 0, 1, -1, 1, -1, -1, 1 };int b[] = { 1, -1, 0, 0, 1, -1, 1, -1 }

調試ncurses程式(把I/O重新導向到其他終端)

ncurses算是一個管理字元介面螢幕輸出的庫,所以使用ncurses庫寫的程式通常要清空整個螢幕,而且輸出不是一段一段的,而是有格式有布局的,這在用gdb調試時按照預設的形式是很彆扭的,會使輸出很混亂,所以我們在調試ncurses的程式時,要對gdb進行一些設定,以便我們找到錯誤的所在。一個方便的辦法是把我們要調試的程式的輸出都重新導向到另一個終端上,這樣就會把gdb的命令提示和我們的輸出分開了,具體的方法是這樣的:我們開啟兩個終端(一個用來使用gdb,另一個用來顯示所偵錯工具的輸出),這兩個

curses 庫筆記

1.cbreak():調用cbreak函數後,除了"Del"和"Ctrl"鍵外,接受其他所有字元輸入。2.raw()和cbreak()兩個函數都可以禁止行緩衝(line

100個經典的動態規劃方程

1.資源問題1-----機器分配問題F[I,j] = max(f[i-1,k]+w[i,j-k]) 2.資源問題2------01背包問題F[I,j] = max(f[i-1,j-v]+w,f[i-1,j]);  3.線性動態規劃1-----樸素最長非降子序列F = max{f[j]+1} 4.剖分問題1-----石子合并F[i,j] = min(f[i,k]+f[k+1,j]+sum[i,j]); 5.剖分問題2-----多邊形剖分F[I,j] = min(f[i,k]+f[k,j]+a[k]

HEU euler path

歐拉迴路#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int N = 110;int n, m, T;int s, e;int g[N][N];int main(){ scanf("%d", &T); while ( T-- ) { scanf("%d%d", &n, &m);

sicp 習題2.24 && 2.25

它的盒子圖形如下: (1 (2 (3 4))) ((2 (3 4)))[*]---------------> [*] | | | | v v (2 (3 4)) ((3 4)) 1 [*]---------------> [*] | |

UVa 315 Network ( 求割頂)

這道題很簡單,就是一道模板,求一共有多少個割頂。開始時候,模板理解得有點偏差,不過好在又想了想。這裡要注意的是,主函數裡面的那個for迴圈是必要,一面一個圖有多個連通分量。同時,還要注意不要忘記填加vis這個標記,如果不添加vis也是可以的,因為pre也是一樣的功能。代碼:#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N =

codeforces 304 B. Calendar

題目連結就是給你兩個日期,讓你求兩個日期之間差多少天。我先算出兩個日期分別是公元多少天,然後相減得到結果。//cf 304B//2013-06-05-18.38#include <stdio.h>#include <stdlib.h>int y, m, d;int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int loop(int y){ if (y%4 == 0 &&

796 Critical Links( 求無向圖中的橋–模板)

很典型的求無向圖的橋個數,並且輸出代碼:#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int N = 110;int n, ans, g[N][N];int dfs_clock, pre[N], low[N];bool is[N][N];int dfs( int u, int fa ){

sicp習題2.2

;; segment cons fuction(define (make-segment start-point end-point) (cons start-point end-point))(define (start-segment segment) (car segment))(define (end-segment segment) (cdr segment));; point cons fuction(define (make-point x y) (cons x

sicp 習題2.3

#lang planet neil/sicp;; init the cons and other basic fuction(define (make-point x y) (cons x y))(define (x-point point) (car point))(define (y-point point) (cdr point))(define (make-segment start end) (cons start end))(define (start-segment seg)

ZOJ 1002 Fire Net

//類似八皇后問題,只需要用DFS回溯即可,注意要一行一行一列一列地掃,不能直接用4個方向的DFS遍曆#include <stdio.h>int N;int cal, max;char map[10][10];int canput( int x, int y );void dfs( int cal );int main(){while ( scanf( "%d", &N ) && N ){int i, j;getchar();cal = 0;max = -10

hdoj 4551 生日猜猜猜

題目連結//hdoj 4551//2013-05-26-20.52#include <stdio.h>int day[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};int judge(int y){ if (y%4 == 0 && y % 100 != 0 || y % 400 == 0) return 1;

總頁數: 61357 1 .... 15174 15175 15176 15177 15178 .... 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.