題意:給一串由ox組成的字串,根據x為 0 分,o為 1 分,當o連續多個時o的分數為它前面連續0的個數。
解法:統計連續o的個數就好啦。用乙個標記變數tag來計算,遇到x時tag = 0,遇到乙個o就對tag進行+1。到每個位置只要累加tag就好了。
#include
#include
#include
#include
using
namespace
std;
int n;
int main ()
cout
《題目描述的很清楚,迴圈1 to n,通過%和/把每個陣列的各個數字都取出來,用乙個陣列來統計每個數字出現的次數。最後輸出結果。
#include
#include
#include
#include
using
namespace
std;
int main ()
}for (int i = 0; i <= 8 ; i++)
printf("%d ",a[i]);
printf("%d\n",a[9]);
}}
題意:求字串的最小迴圈長度。
解法:迴圈結長度肯定是字串長度的乙個約數。那麼就可以迴圈i = 1 to length,當前i時length的乙個約數時,判斷是不是迴圈結。因為是從小到大迴圈,第乙個滿足的肯定時最小的。
#include
#include
#include
#include
using
namespace
std;
string s;
int n,ans;
int main ()
if (tag == 0)
}printf("%d\n",ans);
if (n) printf("\n");
}}
題意:給乙個5*5的字元矩陣,然後會給若干個指令(ablr)以數字0結尾。求經過這些指令操作之後的矩陣。若中間出現了越界,則輸出 「this puzzle has no final configuration.」。
解法:這是一道純模擬題,關鍵在於指令只說明以數字0作為結束標誌,可能出現指令是多行的,中間有空格等等情況。
#include
#include
#include
#include
using
namespace
std;
const
int t[4][2]=,,,};
char
map[8][8];
int x,y,n,m;
int main ()
for (int i = 1 ; i <= 5 ; i++)
for (int j= (i ==1 ? 2 : 1) ; j <= 6 ; j++)
}scanf("%c",&c);
tag=0;
while (c != '0')
if (c == 'b')
if (c == 'l')
if (c == 'r')
if ( x + n < 1 || x + n > 5) tag=1;
if ( y + m < 1 || y + m > 5) tag=1;
scanf("%c",&c);
if (tag) continue ;
map [x][y] = map [x+n][y+m];
map [x+n][m+y] = ' ';
x=x+n;
y=y+m;
}scanf("%c",&c);
num++;
cout
<<"puzzle #"
<':'
}else
cout
<<"this puzzle has no final configuration."
if (map[1][1] != 'z') cout
《解法:
給整個矩陣外面加一圈 * 。
首先對矩陣進行編號,一行一行往下,每乙個前乙個或上乙個為 * 且本身不是 * 的都是乙個單詞的開端。
橫著輸出單詞時就選擇每乙個前面是 * 且本身不是 * 的位置開始輸出。
豎著輸出單詞時就選擇每乙個上面是 * 且本身不是 * 的位置開始輸出。
#include
#include
#include
#include
using
namespace
std;
int n,m,tag1,tag2,num;
char c[100][100];
int z[100][100];
int main ()
num++;
cout
<<"puzzle #"
<':'
<<"across"
cout
<<"down"
for (int j = 1; j <= m; j++)
if (c[i][j] != '*' && c[i-1][j] == '*')
cout
if ( n ) cout
《題意:求乙個長度為n的dna序列,和已知的 m 個長度為n的dna序列誤差最小,並輸出誤差數。
解法:要誤差最小,那麼就取每乙個位置上出現最多的那個鹼基。題目要求多個解時取字典序最小的那個。在處理時可以按字典序來處理acgt,比較時取 > ,這樣就可以保證相同時取字典序小的了。
#include
#include
#include
#include
using
namespace
std;
char s;
int n,m,sum[1200][5],tot;
int main ()
while (s != '\n') scanf("%c",&s);
}for (int i = 1; i <= m; i++)
if (z == 1) printf("a");
if (z == 2) printf("c");
if (z == 3) printf("g");
if (z == 4) printf("t");
tot-=sum[i][z];
}cout
《題意:求s能否通過對t進行更改獲得。
解法:用兩個變數 i , j 表示當前操作到 s 串和 t 串的位置。每次都對 j+1,當s[i] == t[i] 時就對 i+1。當結束的是哈 i >= s.length 就表示可以。
#include
#include
#include
#include
using
namespace
std;
string a,b;
int main ()
if (i >= a.length()) cout
<<"yes"
cout
<<"no"
《題意:給6個矩形的長寬,求這6個矩形是否能拼成乙個長方體。
解法:要想拼成長方體就要想想有什麼約束條件。
1、每個面都要找到乙個和它相同的面
2、不同長度的邊最多有3種,且每種出現的次數是4的倍數
#include
#include
#include
#include
using
namespace
std;
int t[50],lt,z[50],a[8],b[8];
void check (int x)
lt++;
t[lt]=x;
z[lt]=1;
}void ans()
for (int i = 1; i <= lt; i++)
if (z[i] % 4 != 0)
for (int i = 1; i <= 6; i++)
if (k)
}cout
<<"possible"
for (int i = 2; i <= 6; i++)
}ans();
}}
題意:給兩塊由高度為1或2的齒輪鏈,求用多長的高度為3的齒輪鏈可以裝下給定的兩個齒輪鏈。
解法:從第乙個位置開始列舉,判斷另乙個能不能放上來,第乙個能放上來的位置和被列舉的鏈長度中取最打乙個。然後兩個都列舉完取最小的那個,就是答案。
#include
#include
#include
#include
using
namespace
std;
string s1,s2;
int l1,l2;
bool check1 (int x)
bool check2 (int x)
int main ()
}
近期題目整理 6 1
計算 sum x j mod 其中,p 為質數,n le10 9 結論很簡單,以下式子成立 sum xj mod 0 那麼我們只要求最後3項就可以獲得答案 這個結論可以依靠打表獲得,比賽時很多隊依靠打表發現了結論輕鬆的過了這題,而我們的電腦空閒長達1個小時卻沒有嘗試打表。對於一些沒有思路的題目不妨可...
數論 Day2 基礎歸納法 題目
數論進入第二天的學習!今天的主題是基礎歸納,這是一種重要的方法!題解 日期序號題目名稱 輸入檔名 輸出檔名 時限記憶體 演算法難度 分類081105 1燒水問題 heat.in heat.out 1s256mb數學2 03數論 歸納 120912 2六邊形 hexagons.in hexagons....
CSS知識歸納 2
每個元素都有其對應的盒模型 border邊框,border width border style solid實線 dashed虛線 dotted點狀 double雙線 border color padding內邊距 margin外邊框,可以為賦值,使元素內容區域向外展開 元素間上下外邊距會合併,取兩...