Time of Update: 2018-12-05
雖然代碼短,但是還是有很多地方值得學習的。 動規,主要還是狀態轉移方程。還不會寫,參考 http://blog.csdn.net/tclh123/article/details/6286833。 同時還要注意避免重複,一個是通過從最大的硬幣開始,50,25,10,5,1,dp裡面的for迴圈也是從i=a到i=0,然後vis數組標記,避免重複計算,節省時間。#include<cstdio>#include<cstring>
Time of Update: 2018-12-05
這個題比較坑。。。。但是主要是一下三點:1:IP由四個整數跟3個‘.’組成。2:整數必須的0-255的範圍內,並且整數的位元是1-3。3:不能有除了數字和‘.'之外的字元出現。#include<cstdio>#include<cstring>#include<cctype>using namespace std;int main(){ //freopen("in.txt","r",stdin); char str[110];
Time of Update: 2018-12-05
還是比著葫蘆畫瓢,按照UVA439的思路,只是把二維的數組改成三維的,因為對u的計算馬虎了,、wa了6,7次,,55555555,太馬虎了。#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int dist[35][35][35],vis[35][35][35],q[50003],m,r,c;int dx[]= {1,-1,0
Time of Update: 2018-12-05
WA了一次,因為考慮用long long沒有考慮全。這個題類似於以前的括弧題,求maximum就是先算加法,把和存起來,最後乘;求minimum就是先算乘法,最後加。#include<cstdio>#include<cstring>#include<iostream>#include<cctype>using namespace std;int main(){ //freopen("in.txt","r",stdin);
Time of Update: 2018-12-05
題目連結MediandynamicMax Score: 67The median of M numbers is defined as the middle number after sorting them in order if M is odd or the average number of the middle 2 numbers (again after sorting) if M is even. You have an empty number list at first.
Time of Update: 2018-12-05
做的第一個歐拉迴路的題目,參考的一篇部落格。。。。。#include<cstdio>#include<cstring>using namespace std;int g[1010][1010],vis[55];int count,num[51],colornum,cnt,c;void dfs(int a){ vis[a]=1; cnt++; for(int i=0; i<51; i++
Time of Update: 2018-12-05
這個題類似於求最大上升子列那種,最多可以放3*n種磚塊,枚舉,讓每塊磚作為最底下的那塊。d[i]表示第i塊磚放在最下面時的最大高度,d[i]=max{d[j]+h[i]},j是可以嚴格的比i的磚,h[i]是i的高度。WA了7遍,是因為磚是從下標0開始存的,這樣如果是210 20 10010 10
Time of Update: 2018-12-05
基本上是比著別人的代碼自己寫了一遍。思路就是一個bfs,方法感覺和uva 439 Knight Moves很類似,之前還不是很理解為什麼非要有一個隊列來存各種狀態,原因就是從最初的0,0,b到倒水,可以形成幾種狀態,把這幾種狀態用隊列存起來,利用隊列先進先出的特性,一次對每一種狀態進行拓展。判斷可行的條件是:1.這個狀態未曾被訪問到;2.從a杯到b杯倒水時,b杯還是未滿的,a杯不是空的;#include<cstdio>#include<cstring>
Time of Update: 2018-12-05
題意很簡單,輸入n,k,有k種小球,要拿n種,要求每種小球都至少要拿一種,很經典很直白的排列組合問題,就是高中學過的插空法,有n-1個空,插入k-1個隔板,有多少種插法。百度文庫中的例子:擋板的使用例20.10個名額分配到八個班,每班至少一個名額,問有多少種不同的分配方法?分析:把10個名額看成十個元素,在這十個元素之間形成的九個空中,選出七個位置放置檔板,則每一种放置方式就相當於一種分配方式。因而共36種。 組合數公示:c(n,m)=p(n,m)/m!=n!/((n-m)
Time of Update: 2018-12-05
遞迴學習中。。。。。感覺這個題主要就是遞迴的運用,代碼:#include<cstdio>#include<cstring>#include<cstdlib>typedef struct Node{ int val; struct Node *left,*right;} Node;int n,m;int num[85];Node *buildtree(){ scanf("%d",&n); Node
Time of Update: 2018-12-05
給一個區間,每一個區間都有自己的價值屬性,選擇價值和最大的不相交的區間。方法排序+dp+二分尋找區間,最重要的是狀態轉移方程,dp[i]=max{dp[c]+a[i].v,dp[i+1]}; a是起點>=i的終點的結點,p[i]是i的價值。按照起點從小到大對a數組排序,然後從起點最大的點開始,對於每一個a[i],有兩種選擇,一是選擇這一區間,二是不選擇。如果選擇,那麼這時的總價值是dp[c]+a[i].v,如果不選擇,dp[i]=dp[i+1],#include<
Time of Update: 2018-12-05
A. Perfect Pairtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3,
Time of Update: 2018-12-05
完全模仿《演算法競賽入門經典》,寬度優先遍曆。。。神奇的遞迴。。。還有8方向遍曆的方法。模版#include<cstdio>#include<cstring>using namespace std;char map[110][110];int vis[110][110];void dfs(int i,int j){ if(map[i][j]=='*'||vis[i][j]==1) return ; vis[i][j]=1; dfs(i,j+
Time of Update: 2018-12-05
這是個類比題,但是由於資料量很大,不能只是單純的類比,但是細節的處理很重要。核心思路是每一步找出最小的時間,取整得到min.然後每一步應該是每一個任務的時間-(min-1),這樣方便計時。#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>using namespace std;int
Time of Update: 2018-12-05
比賽的時候沒怎麼讀懂題目,其實就是找>=給出的數的迴文數。設原先的月薪為a,迴文月薪b,先讓a的前半部分等於b,再對稱著補全b的後半部分,然後判斷這時候b比a大,直接輸出,否則把b的前半部分加1,再對稱著找出後半部分。輸出即可。#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#define MAXN 2010using
Time of Update: 2018-12-05
題目連結 DescriptionFor each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know
Time of Update: 2018-12-05
其實是一道挺簡單的題,比較重要的資訊就是提供的第一條充要條件。依據這個可以判斷【m,n】是否為【p,q】的因子。怎麼找到這些符合的m,n呢?不用太多技巧,只要挨個數試可以了。這裡要注意 1 < m2 + n2 <
Time of Update: 2018-12-05
Online JudgeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3878 Accepted Submission(s): 1452Problem DescriptionIgnatius is building an Online Judge, now he has worked out all the problems
Time of Update: 2018-12-05
比賽中我最大的失誤:輸入的兩個數字先是寬,再是高,而我沒有注意到,按往常先高後寬做的,一直到最後沒有AC,事實上思路是對的。 #include<cstring>#include<cstdio>using namespace std;int main(){ char c; int x,y,cas; scanf("%d",&cas); getchar(); while(cas--) {
Time of Update: 2018-12-05