ZOJ 3474 Taekwondo

TaekwondoTime Limit: 2 Seconds      Memory Limit: 65536 KBAlice is very fond of Taekwondo and he is also a member of Taekwondo Association of Zhejiang University. One day, his friends decide to compare with him. Now Alice must face all of his

ZOJ 1877 Bridge

BridgeTime Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judgen people wish to cross a bridge at night. A group of at most two people may cross at any time, and each group must have a flashlight. Only one flashlight is available among

UVa 11218 – KTV

題意:讓你從n種搭配中,選出3個,使得選出的9個數字巧好是“1~9”不重複,在所有合格情況中輸出分數最高的情況。解法:dfs回溯,即:枚舉出所有合格情況從中選出分數最高的那個。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using

UVa 507 – Jill Rides Again

最大連續和問題,注意其還有一要求是需要路徑最長,即:當其和相同時,取路程最大的一段路的起點和終點,也就是說如果其和相同但其路徑較短則不必更新先前儲存的起點與終點位置。代碼如下:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>#include<ctime>using namespace std;int

UVa 714 – Copying Books

“最大值最小化”問題,先二分求最大值,再貪心實現按最左邊區間最小的格式輸出 。代碼如下:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>using namespace std;int main(){#ifdef test freopen("in.txt", "r", stdin);#endif int a[5

ZOJ 1577 – GCD & LCM

GCD & LCMTime Limit: 2 Seconds      Memory Limit: 65536 KBGiven x and y (2 <= x <= 100,000, 2 <= y <= 1,000,000), you are to count the number of p and q such that:1) p and q are positive integers;2) GCD(p, q) = x;3) LCM(p, q) =

UVa 705 – Slash Maze

將整個映像放大兩倍後,其中間空格數恰好為所求空格數,注意整個映像外圈需要圍上一圈"#"號以作邊界;然後DFS 8個方向進行深度優先搜尋,這裡需注意,有對角線的四個方向需要特殊條件(判斷是否相通)才可遍曆,否則不遍曆 ~代碼如下:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#define max 100+5int num,max_l,t,fflag,vis[

UVa 10714 – Ants

經分析,最小值就是看最靠近中間的點到其較近的端點的距離,最大值為最小點距右端點的距離與最大點距左端點的距離中的較大的那個。代碼如下:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>using namespace std;const int maxn = 1000002;int cmp(const void *a,

UVa 10465 – Homer Simpson

可以用完全背包來做,也可以用貪心的方法來做。貪心的話:(1)如果恰好可以湊成t,則更新最大漢堡數(即:A+B最大)。(2)如果湊不成t,則在 t-max最小的情況下,更新A+B的最大值。貪進法(0.024s):#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int _max;int main(){#ifdef

UVa 10285 – Longest Run on a Snowboard

算最長路,最長上升子序列的變形。代碼如下:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int dp[101][101], graph[101][101];int n, r, c;int DP(int i, int j){ if(dp[i][j] > 0) return dp[i][j]

UVa 10720 – Graph Construction

貪心,為保證其儘可能為圖,要優先考慮大度數之間的點優先串連。在這裡可以採取依次減度數的方法推斷能否構成圖。如:3,3,2,2,1五個點,從度數最大的開始考慮,先去掉3,則後面緊接的三個點度數依次減去1,剩下的四個點排序後為2,1,1,1,再去掉度數最大的2,後面的兩個點一次減去1,排序後剩下三點為1,0,0,1後的一點度數再減去1,則為-1,明顯不成立,為Impossible。代碼如下:#include<iostream>#include<cstdlib>#include

UVa 10041 – Vito’s Family

這個題在上機時敲的,乍一看好簡單(其實確實也不難,就是中位元做差求和的問題),本來說要秒殺的,結果WA了好幾遍,仔細分析後又是沒讀透題意,把當房屋為偶數時的中位元的情況當成了是中間兩個數之和的一半了,為此還用double型的量寫的好長(白費力氣了),實質上它是不允許“另外建房子的”,也就是說是在已知家庭的家庭中挑一個家庭住,偶數時只要在中間兩個家庭中選一個就好(其實選哪個算出的值都一樣的), 改完後AC了

993 – Product of digits

描述:題意就是從1-9之間找出一堆數相乘的積就是輸入的數值,如果沒有,就輸出-1#include <cstdio>#include <cstdlib>int main(){ // freopen("a.txt","r",stdin); int n,x; scanf("%d",&n); while(n--) { scanf("%d",&x); if(x>=10) {

UVa 216 – Getting in Line

乍一看,像最小產生樹,實際不用,因為資料量較小(最大8台電腦),所以直接類比全排列算最小值就可以。代碼如下:#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;struct point{ int x, y;} po[10];int n;double save_d[10]

UVa 167 – The Sultan’s Successors

經典“八皇后問題”,把所有情況全部遍曆一遍,統計最大值即可。代碼如下:#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int a[9][9], vis[3][20], save[9], n, tot;void search(int cur){ int i;

UVa 140 – Bandwidth

全排列,統計記錄每個排列中“頻寬”最大的值,最後輸出所有最大值中最小的那個。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int cct, ahl[27], map[27][27];int save[9],

UVa 10115 – Automatic Editing

大體題意就是將列表第一列的字串不斷換成第二列的字串,直到將所給的整個句子中所有出現的第一列字串全部換掉為止,然後再進行下一個字串的替換。題目本身不難,相信只要認真一點,就可以輕鬆AC掉 ~(如果用上strstr()函數和sprintf函數會使代碼簡潔不少,效率也會提高不少。當然如果會用STL的string的話,同樣會很快。)代碼如下:#include<stdio.h>#include<string.h>#include<math.h>int

HDU 4403 A very hard Aoshu problem

回溯,兩個數字之間標記0,1,最後將標記1的位置放‘+’號,‘0’的位置處兩邊數字合成一個數,最後將每兩個數之間放等號,檢查是否相等。代碼如下:#include <iostream>#include <algorithm>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;int len, num[1

UVa 141 – The Spot Game

題意實際上要求每次比較四個圖形(其中三個是旋轉翻轉得到的),然後通過比較如果這四個圖形之前都沒有出現過,則將這四個圖形全部存起來,以備以後進行比較(還有一點需要注意的,就是如果原圖形經過旋轉得到的圖形和原圖形相同,這種情況是不算重複的)。剛開始理解成每次幾個比較完之後只把原圖形存起來了,WA了好幾次。方法:因為資料量較小,直接將二維圖存成一維數組,然後暴力枚舉比較就可以。代碼如下:#include <iostream>#include

UVa 188 – Perfect Hash

按照題目說的去類比就可以,唯一值得注意的是,兩個單詞之間可能不止一個空格,因為這個RE了好幾次。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int main(){#ifdef test

總頁數: 61357 1 .... 7900 7901 7902 7903 7904 .... 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.