Time of Update: 2018-12-03
//11074526c00h00g1042Accepted572K125MSG++3624B2012-12-03 19:05:06//思想:枚舉,使用優先隊列實現的,見黑書 //tm數組竟然不能開//runtime error,開始理解錯了,以為是將時間加到第一個捕到魚的湖上面,其實是加在第一個湖上面就行了
Time of Update: 2018-12-03
//貪心//怎麼看都覺得測試資料的l和w是反著的//11075395c00h00g1065Accepted200K16MSC++1172B2012-12-03 22:14:06 #include<stdio.h>#include<stdlib.h>#include<algorithm>using namespace std;struct Node{ int l,w;};Node stick[5005];bool visited[5005];int
Time of Update: 2018-12-03
#include<stdio.h>#include<stdlib.h>#include<string.h>int a[8];int vis[8];int sum,count,n;int x,flag;int Pow(int x){ int res=1; for(int i=1;i<=x;++i) res*=10; return res;}void dfs(int i){ if(count==7){
Time of Update: 2018-12-03
//11084954c00h00g1160Accepted784K47MSG++1100B2012-12-06 22:48:58//dp[i][j]表示前i個村莊建立了j個郵局//dp[i][j]=min(dp[k][j-1]+cost[k+1][i]) 1<=k<=i-1 感覺這一題和龜兔賽跑那個題目有點相似 #include<stdio.h>#include<stdlib.h>#include<string.h>using
Time of Update: 2018-12-03
//簡單的kmp匹配,尋找子串的個數,找到一個之後移動相應的指標就行了 #include<iostream>using namespace std;char a[1005];char b[1005]; int next[1005];void get_next(char const* ptrn,int plen,int* next){ int i=0; next[i]=-1; int j=-1; while(i<plen-1){ if(j==
Time of Update: 2018-12-03
//71025762012-11-06 23:49:51Accepted15030MS408K1796 BG++chen//1A 只需記錄一下共同的位置,然後分段輸出就行了 #include<iostream>using namespace std;char x[105];char y[105];int c[105][105];int posx[105];int posy[105];int m,n,i,j,len,num;void lcs(){ for(i=1;i<=m;
Time of Update: 2018-12-03
//第一道狀態dp,要理解那張圖 //要學會定義變數 #include<iostream>#include<string>#include<limits.h>using namespace std;struct Homework{ string name; int deadline; int costime;};Homework work[16];struct DP{ int before; int now;
Time of Update: 2018-12-03
直接用插入排序做就行了,題目中說有序,但沒有說明是遞增還是遞減,我是按照遞增做的class Solution {public: void merge(int A[], int m, int B[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function //插入排序 int i,j;
Time of Update: 2018-12-03
//11058973c00h00g2049Accepted1436K63MSG++2671B2012-11-28 15:18:51//使用c++提交會WA,是double轉化為整形的時候出錯了//原因:直接強制轉換時不準確的,需要這樣轉化 dx=(int)(tmpa+0.0001);加上一個位移量,不然的話//如果題目中給定的是1,但在電腦中可能是0.9999999,然後強制轉化就可能變成0,會導致錯誤//題目思路:將每個正方形用左下角座標來表示,主要有三種狀態,牆,門,空氣,初始化的時候將//
Time of Update: 2018-12-03
//直接打表了,connect[x][y][z]表示x的z方向上的y,他們之間是否連通,x,y的取值為0-10,//分別代表那11中類型,z表示方向0表示右方,1表示上方,2表示左方,3表示下方//72363122012-11-23 22:37:23Accepted119815MS1552K2455 BG++chen #include<stdio.h>#include<stdlib.h>#include<string.h>int N,M;int
Time of Update: 2018-12-03
//11062096c00h00g2479Accepted984K438MSG++859B2012-11-29 14:25:42//分成兩段left和right//left[i]表示包含aa[i]的最大連續欄位和,right[i]表示從後向前包含aa[i]的最大欄位和//由於left[i]並不能表示1-i的最大欄位和,故需要設計一個變數ll來表示左端的最大值//錯誤原因; 見代碼描述 #include<stdio.h>#include<stdlib.h>#include&
Time of Update: 2018-12-03
//這裡有兩個地方需要注意//1.marble+N指向數組結尾處之後的下一個元素,如果讓end指向最後一個元素的話,則//應為sum(marble,marble+N-1);而且函數應該改為while(begin<=end),這種寫法不整潔//而且不容易被記住,容易導致編譯錯誤。這讓我想到,c++中的迭代器iterator設計的時//候也是遵循的這個原則//2.*和++具有相同的優先順序,它們結合時是從右向左進行的,先進行++操作。#include<stdio.h>#includ
Time of Update: 2018-12-03
//問題描述,這是一道典型的塗色問題,根據四色定理,最多不會超過4中顏色,所以只需要 //枚舉1-3種顏色就行了 //對每一個節點來說,用k=1-cor顏色開始塗色,判斷每種顏色是否可以使用,如果可以使用的話,//則圖成該種顏色,改圖下一個節點 //11052306c00h00g1129Accepted180K0MSC++1731B2012-11-26 15:17:06
Time of Update: 2018-12-03
//11102903c00h00g1797Accepted4364K407MSG++1481B2012-12-12 22:30:50//最短路徑重新定義為:從1-n的一條路徑中,最短的那條邊的長度。然後求出所有最短邊中的最大值 //只是貪心的策略改變了,每次尋找最大的d進行鬆弛 #include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>using
Time of Update: 2018-12-03
你是在虛擬機器上安裝的Linux吧?如果想讓linux識別隨身碟,需要把滑鼠先定位在虛擬機器的linux裡面,然後插入優盤,優盤才會被linux識別,再用fdisk -l 來查看隨身碟的情況。/dev/sda1 * 1 6 48163+ 83 Linux/dev/sda2 7 515 4088542+ 83 Linux/dev/sda3 516
Time of Update: 2018-12-03
//11068092c00h00g1050Accepted4736K47MSC++1140B2012-12-01 13:59:06//參考的編程之美上給出解法//收穫:對於一維的數組a[i],要求其最大連續子串和,我們只需要設計一個變數tmp=0(初值)//for(int i=1;i<=n;i++){// tmp=max(tmp+a[i],a[i])// }而不需要設計dp[i]
Time of Update: 2018-12-03
//使用short能過,使用int會超記憶體,公用個數總共也就5000,所以short是可行的 #include<iostream>using namespace std;char x[5005];char y[5005];short c[5005][5005];int len;int i,j; int comlen;void lcs(){ for(i=1;i<=len;i++) c[i][0]=0; for(j=1;j<=len;j++)
Time of Update: 2018-12-03
//11062096c00h00g2479Accepted984K438MSG++859B2012-11-29 14:25:42//分成兩段left和right//left[i]表示包含aa[i]的最大連續欄位和,right[i]表示從後向前包含aa[i]的最大欄位和//由於left[i]並不能表示1-i的最大欄位和,故需要設計一個變數ll來表示左端的最大值//錯誤原因; 見代碼描述 #include<stdio.h>#include<stdlib.h>#include&
Time of Update: 2018-12-03
//分層遍曆#include<iostream>#include<queue>using namespace std;struct Node{char data;int level;Node *left;Node *right;};//寫了這麼長時間才發現要這樣寫,不這樣寫會出錯,為什嗎?//就像一個函數如果只是傳入值的話,結果並不改變//比如,int a=5;void add(int a){a++}
Time of Update: 2018-12-03
這裡我們只討論整數的情況,因為acm中經常要用到。我先幾個簡單的,大家都能說出結果的:#include<iostream>using namespace std;int a[10];int main(){memset(a,0,sizeof(a));//結果為0memset(a,255,sizeof(a));//結果為-1return