Time of Update: 2018-12-05
這章什麼高效演算法設計啊,這題初看貌似很高端,後來分析了集中情況,這連類比題都不是,最弱智的數的大小,好吧,主要是分析螞蟻極端情況,思路我就不透露了#include <stdio.h>#include <stdlib.h>int ants[100000];int main(){int len, t, max, min, n, lin;scanf( "%d", &t );while(t--){scanf( "%d %d", &len, &n
Time of Update: 2018-12-05
思路題吧,和SGU231一樣,time limit per test: 0.5 sec. memory limit per test: 4096 KB。
Time of Update: 2018-12-05
這個題關鍵是讀懂題目意思:一棵樹,結點按照1--N編號,然後刪除當前度數為1的結點中標號最小的一個結點,同時寫下這個結點相關聯的點的標號,重複這一動作,一直到只剩下一個結點為止。範例解釋:輸出的有2 1 6 2 6,說明1,2,,6這三個結點肯定不是度數為1 的,第一個葉子刪的一定是3,並且3和2相連,然後後面剩下的是1 2 6說明刪除的是4,4和1相連,這時候剩下的是2 6 同時3,4已經被刪除,那麼下一步刪的一定就是1了,(因為這時候剩下的葉子有1 和5,1最小),
Time of Update: 2018-12-05
這個題要特別注意time limit per test: 0.5 sec. memory limit per test: 4096 KB,所以在構造素數表以及標記數組都要特別注意。#include<cstdio>#include<cstring>#include<iostream>using namespace std;int isprime(int n){ for(int i=2; i*i<=n; i++) if(
Time of Update: 2018-12-05
1硬幣翻轉在案頭上有一排硬幣,共N枚,每一枚硬幣均為正面向上。現在要把所有的硬幣翻轉成反面朝上,規則是每次可翻轉任意N-1枚(正面向上的被翻轉為反面向上,反之亦然)。求一個最短的操作序列(將每次翻轉N-1枚硬幣成為一次操作。輸入:只有一行,包含一個自然數N(N不大於是100的偶數)。輸出:第一行包含一個整數S,表示最小需要的操作次數。接下來的S行每行分別表示每次操作後的硬幣的狀態(一行包含N個整數0或1),表示每個硬幣的狀態。0—正面向上,和1—反面向上,不允許出現多餘空格。對於多種操作方案的情
Time of Update: 2018-12-05
第一次寫CSDN的部落格,感覺它的xhEditor用的不是那麼順手,這篇文章是我們課程WBIA(Web Based Information
Time of Update: 2018-12-05
#include<cstdio>#include<cstring>using namespace std;int n,m,k,seat[30],accept[30],max;typedef struct ord{ int start,end,number,earn;} ord;ord order[30];void dfs(int stop,int money,int cur){ max=max>money?max:money;
Time of Update: 2018-12-05
Louis 的兩種方法都不對,第一種方法list 的順序反了,第二種方法最後構造出的是一個表頭為空白,後面是值的序對。 list 應該表頭就是第一個元素。正確的迭代方法:(define (square-list items) (define (iter things answer) (if (null? things) (reverse answer) ; change 當最後迭代完以後 list為逆序, 調用reverse
Time of Update: 2018-12-05
為什麼肯德基和麥當勞總是開在一起?--用博弈論中的嚴格非優策略的迭代刪除法分析 我們經常會有這樣的發現,在一個城市的繁榮地帶,你發現了一家肯德基,環顧四周,通常也會在附近發現一家麥當勞。那麼,為什麼肯德基和麥當勞總要開在一起,從而相互競爭,喪失人流呢?這裡我將從博弈論中嚴格非優策略的迭代刪除法來嘗試解釋這種情況。 首先,為了方便分析,我們假設如下模型。 1.一條公路分成1-10節路,每節路的人數相同,都為1個單位的人群,1。
Time of Update: 2018-12-05
題目連結題意: 有一字串只包含0和1,然後又m組操作,I L R是將從L到R的字元進行翻轉操作0變為1、1變為0,Q x表示詢問第x的字元。思路: 我們只需要計算對詢問的字元進行了多少次翻轉,如果是偶數次,該字元變,否則翻轉。對於區間的更新,我們可以使用線段樹,不過對於這個題,因為只是對點的查詢,而且每個節點的初始值都相同,為0,因此我們可以直接使用樹狀數組。下面是一個很巧妙的做法,而且很容易理解。用了樹狀數組的區間更新 單點尋找(一般為單點更新 區間尋找)例如
Time of Update: 2018-12-05
題意: 有n個數,有m組操作,1 i表示將第i個數先輸出,然後置0, 2 i v 表示給第i個數加上v, 3 i j 表示求i 到 j 的和,注意,這裡數組是從0開始的,而我們構造的樹狀數組是從1開始的,使用在程式中要進行一定的處理。//LA 1112 - Curious Robin Hood(樹狀數組)//2013-04-13-08.22#include <stdio.h>#include <string.h>const int maxn = 100010;int
Time of Update: 2018-12-05
題目連結DescriptionBessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weightWi (1
Time of Update: 2018-12-05
看上去是個圖論題,其實可以從裡面抽象出一個數學模型的。如果有m個連通分支,一共n個點,每個連通分支點的個數分別是a1,a2,,,,an那麼a1*(n-a1)+a2*(n-a1-a2)+a3*(n-a1-a2-a3)+........=k。通過這種方法寫的dfs不需要很多的剪枝。代碼如下:#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib&
Time of Update: 2018-12-05
題目連結DescriptionA train has a locomotive that pulls the train with its many passenger coaches. If the locomotive breaks down, there is no way to pull the train. Therefore, the office of railroads decided to distribute three mini locomotives to each
Time of Update: 2018-12-05
sudo add-apt-repository ppa:bumblebee/stablesudo add-apt-repository ppa:ubuntu-x-swat/x-updatessudo apt-get updatesudo apt-get install bumblebeesudo apt-get install bumblebee-nvidia sudo reboot以上命令是安裝bumbleebee執行如下命令lspci |grep VGA如果輸出類似這2行:00:02.0
Time of Update: 2018-12-05
dfs第一遍找到海,標記出來;第二遍,把海外面的部分dfs標記出來;第三遍找陸地。 第二遍dfs的起點是圖的四周所有的點,這樣4個方向dfs就把不被海包圍的東西標記了,剩下的一定是被海包圍的。 這個題比較坑的是要讀好題,分清x,y是橫座標還是縱座標。#include<iostream>#include<cstdio>#include<cstdlib>#include<
Time of Update: 2018-12-05
這個題最重要的是一種求組合數的方法。求出所有硬幣的和sum後用 memset(f,0,sizeof(f)); f[0]=1; for(int i=0; i<n; i++) { for(int j=sum; j>=coin[i]; j--) { if(f[j-coin[i]]) f[j]=1;
Time of Update: 2018-12-05
題很簡單,思路也不難,就是一個貪心,但是第一次寫用最直觀的類比,結果導致了TLE,必然,資料量大概是100000,我的程式大概最壞的話應該是個O(n2)TLE 了這是我的TLE代碼#include <stdio.h>#include <string.h>#include <stdlib.h>int a[200000];long long cost;int n;inline int abs( int a ){if( a < 0 )return
Time of Update: 2018-12-05
書上使用c#實現的,我改成了c++,本人屬於菜鳥層級,如有錯誤還請留言指教#include <iostream>#include <string>using namespace std;class Operation{public:double A;double B;virtual double GetResult(){};};class OperationAdd : public Operation{public:virtual double
Time of Update: 2018-12-05
這個題一開始想用dfs但是不知道怎麼剪枝,後來看了http://txhwind.diandian.com/?tag=sgu,在cur>n時調用dfs()函數判斷,滿足則dfs(cur+1),最後在cur>n*n時再check()。#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#define MAXN 9+9using