10個精彩智力問題,看你會做幾道?

希望大家能夠大呼過癮~1. 給一個瞎子52張撲克牌,並告訴他裡面恰好有10張牌是正面朝上的。要求這個瞎子把牌分成兩堆,使得每堆牌裡正面朝上的牌的張數一樣多。瞎子應該怎麼做?2. 如何用一枚硬幣等機率地產生一個1到3之間的隨機整數?如果這枚硬幣是不公正的呢?3. 30枚面值不全相同的硬幣擺成一排,甲、乙兩個人輪流選擇這排硬幣的其中一端,並取走最外邊的那枚硬幣。如果你先取硬幣,能保證得到的錢不會比對手少嗎?4.

POJ 2346 Lucky tickets

DescriptionThe public transport administration of Ekaterinburg is anxious about the fact that passengers don't like to pay for passage doing their best to avoid the fee. All the measures that had been taken (hard currency premiums for all of the

POJ 2075 Tangled in Cables(最小產生樹)

//最小產生樹Kruscal#include<iostream>#include<map>#include<vector>#include<string>#include<algorithm>#define eps 1e-8//精度處理using namespace std;int n,m;struct Edge{int u,v;double w;Edge(int uu,int vv,double ww){u = uu;v =

POJ 2513 Colored Sticks(Trie+並查集+歐拉迴路)

//TRIE + 並查集 + 歐拉迴路//A了這道題,學會了用並查集判斷無向圖的連通性#include<iostream>#include<map>#include<string>using namespace std;const int MAX = 500003;int N;int fa[MAX];int deg[MAX];struct trie{int color;trie *next[26];trie(){color = 0;memset(next,0,

POJ 3349 Snowflake Snow Snowflakes(HASH)

#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int MAXHASH = 100003;bool vis[MAXHASH];bool ok;int state[MAXHASH][6];//存放雪花形狀的狀態int head[MAXHASH],next[MAXHASH];int n;unsigned int hash(int

POJ 2503 Babelfish(HASH)

//字典HASH簡單應用,這題也可用Trie做//學會了SSCANF的使用,痛點在於處理資料的讀入#include<iostream>using namespace std;const int MAXHASH = 100003;int head[MAXHASH],next[MAXHASH];int m;struct Dic{char english[11];char foreign[11];}dic[MAXHASH];int hash(char

POJ 1502 MPI Maelstrom(單源最短路|Dijkstra實現)

//單源最短路。最後答案應該處從起點到其他結點最短路中的最大值。#include<iostream>#include<queue>using namespace std;const int INF = 50000000;int G[105][105];bool flag[105];int dis[105];int n;int dijkstra(int st){int res = INF*(-1);for(int i = 0;i < n;i++)dis[i] =

POJ 2263 Heavy Cargo(圖的遍曆)

//圖的遍曆//CITY記錄到當前城市的的最大運載量//狀態轉移方程,city[y] = max(city[y],min(r[x->y],city[x]);#include<iostream>#include<map>#include<string>#include<queue>using namespace std;const int MAX = 205;const int MAXM = 40000;const int INF = 1000

POJ 1703 Find them, Catch them(並查集)

//並查集,NND忘了個句號WA了3次!//A過POJ1182的食物鏈後再來做這道題就輕鬆多了,這是食物鏈的簡單版//並查集的集合是以能否確定關係來分的,而不是以屬於同一個幫派或不同幫派來分的//這類題只需建立一個並查集,然後維護每個結點和他的根結點之間的關係屬性即可//如果2個點不在同一個並查集中,那麼這2個點無法確定關係//在同一個並查集中的每個點,都能確定集合中的相互關係#include<iostream>using namespace std;struct node{int

KMP演算法詳解自Matrix67大牛)

如果機房馬上要關門了,或者你急著要和MM約會,請直接跳到第六個自然段。    我們這裡說的KMP不是拿來放電影的(雖然我很喜歡這個軟體),而是一種演算法。KMP演算法是拿來處理字串匹配的。換句話說,給你兩個字串,你需要回答,B串是否是A串的子串(A串是否包含B串)。比如,字串A="I'm

POJ 2236 Wireless Network(並查集)

#include<iostream>#include<vector>using namespace std;struct coord{int x,y;}P[1005];int n,d;char cmd;int fa[1005],x,y;vector<int> ok;void init(){for(int i = 1;i <= n;++i)fa[i] = i;}int Find(int x){if(x == fa[x])return x;else

POJ 1502 MPI Maelstrom(單源最短路|Floyd實現)

//單源最短路Floyd實現。最後答案應該處從起點到其他結點最短路中的最大值。#include<iostream>#include<queue>using namespace std;const int INF = 50000000;int G[105][105];bool flag[105];int dis[105];int n;int Floyd(){for(int k = 0;k < n;++k)for(int i = 0;i <

Sicily 1800 Sequence(RMQ)

//RMQ(線段樹求解)//A這道題後,懂得了對數列的轉換,如果要求連續區間和,就必須把它轉化成SUM[I],表示從1到I的區間之和//這樣的話要求任意區間的和,假設[I,J]的和,只需要sum[j] - sum[i-1]就可以立即求出來了//注意sum[0] = 0;//思路:枚舉從L開始到的的sum[i](i >= L)//對符合長度條件的區間中找到一個最大的sum[j] (max(0,i-U) <= j <= i-L)//這樣的話sum[i] -

POJ 1008 瑪雅曆(類比|日期計算)

//一道很不錯的題目。忽略細節WA了3次//要注意特殊情況//如果是一年的最後一天,注意年份必須減1//總結:在做關於模數運算時,注意考慮當結果為0時是否是你要的答案#include<iostream>#include<map>#include<string>using namespace std;map<string,int> stoi;map<int,string>

POJ 1028 Web Navigation

DescriptionStandard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward.

Sicily 1424 獎金(拓撲排序)

//拓撲排序,若a員工工資比b員工多,那麼從b->a建立有向邊//接著從工資應該最小的員工開始逐步向工資最大的員工疊加//注意對DAG環的判斷//注意因為結點數高達10000,因此必須用鄰接表儲存#include<iostream>#include<vector>#include<cstring>#include<queue>using namespace std;const int MAX = 10005;vector<int>

UVaoj 340 Master-Mind Hints

MasterMind is a game for two players. One of them, Designer, selects a secret code. The other, Breaker, tries to break it. A code is no more than a row of colored dots. At the beginning of a game, the players agree upon the length N that a code must

POJ 1094 Sorting It All Out(拓撲排序)

//拓撲排序。每添一條邊就進行一次拓撲排序#include<iostream>#include<vector>#include<queue>using namespace std;int inDeg[26];int n,m,time,u,v;int appear;//已出現的結點數char str[3],topo[26];bool vis[26];vector<int> e[26];queue<int>

POJ 1840 Eqs(枚舉+HASH)

//枚舉 + HASH//第一個最佳化,先預先處理立方,先打個表//第二個最佳化,拆分枚舉,先枚舉X1,X2,再枚舉X3,X4,X5,這樣將複雜度降為O(100^3)//第三個最佳化,搜尋剪枝,枚舉X1,X2的時候記錄結果的最大最小值,當在枚舉X3,X4,X5的時候如果超過這個範圍則跳出//在判重的時候使用HASH,簡單的模數HASH函數即可//處理衝突採用拉鏈法//344MS#include<iostream>#define MAXHASH 916549#define NEG 12

POJ 1275 Cashier Employment(差分約束系統)

摘自馮威論文——《數與圖的完美結合》設num[ i ]為i時刻能夠開始工作的人數,x[ i ]為實際僱傭的人數,那麼x[ I ]<=num[ I ]。 設r[ i ]為i時刻至少需要工作的人數,於是有如下關係:     x[ I-7 ]+x[ I-6 ]+x[ I-5 ]+x[ I-4]+x[ I-3 ]+x[ I-2 ]+x[ I-1 ]+x[ I ]>=r[ I ] 設s[ I ]=x[ 1 ]+x[ 2 ]…+x[ I ],得到     0<=s[ I ]-s[ I-1

總頁數: 61357 1 .... 13013 13014 13015 13016 13017 .... 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.