Time of Update: 2018-12-03
題目:tzc1051方法:大數乘法 大數乘大數代碼:#include <iostream>#include <cstring>using namespace std;void mult(char a[],char b[],char s[]){int i,j,k=0,alen,blen,sum=0,res[500][500]={0},flag=0;char result[500];alen=strlen(a);blen=strlen(b); for
Time of Update: 2018-12-03
題目連結:hdu1069 代碼: //one block could only be placed on top of another block as long as the two base dimensions of the// upper block were both strictly smaller than the corresponding base dimensions of the lower block//write a program that determines
Time of Update: 2018-12-03
題目: tzc1537方法:數論 代碼://k<=10 000#include <iostream>#include <string>#include <cstring>#include <cstdio>using namespace std;int num[10005];int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int judge(int *x,int k){x[2]/=gcd(x[2]
Time of Update: 2018-12-03
題目連結:hdu1466 解題思路:摘自杭電課件動態規劃1 分析加入第N條直線的情況(這裡以N=4為例): (分類方法:和第N條直線平行的在a組,其餘在b組) 1、第四條與其餘直線全部平行 => 0+4*0+0=0; 2、第四條與其中兩條平行,交點數為0+(n-1)*1+0=3; 3、第四條與其中一條平行,這兩條平行直線和另外兩點直線的交點數為(n-2)*2=4,而另外兩條直線既可能平行也可能相交,因此可能交點數為: 0+(n-2)*2+0=4 或者 0+(n-2)*2+1
Time of Update: 2018-12-03
題目連結:tzc2668方法:貪心思想:先將會議進行排序,開始時間早的到前面,然後迴圈,將可以在一個會場可以進行的會議標記為1,最後外迴圈次數就是答案。代碼:#include <iostream>#include <cstring>#include <algorithm>using namespace std;struct node{int s,e; };node meet[1005]; bool visited[1005]; bool
Time of Update: 2018-12-03
題目連結: http://acm.hdu.edu.cn/showproblem.php?pid=4193題目大意:給定一個長度為n的迴圈序列,從n個不同位置開始,問有幾個位置使得一下情況成立:所有首碼的和都大等於0(n <=100萬).解題思路:下午做的swerc的G題,這題想成線段樹敲了十多分鐘,然後TLE了,爾後就去敲第一題Polya,拿了個FB。線段樹之所以會T,是因為它的複雜度是O(nlogn),這樣n等於100萬的時候大概要操作8千萬左右,而用單調隊列只要O(n),運算元大概為2
Time of Update: 2018-12-03
題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1520題目大意:給定一棵關係樹,每個節點有個權值,子節點和父節點不能同時選,問最後能選的最大價值是多少?解題思路:樹形DP入門題。由於子節點與父節點不能同時選,有人可能會用貪心思想,二者選其一肯定最優。其實不然,有可能父節點和子節點都不選,而要選子孫節點。不過只要再往深點想下,就可以得出動態規劃的解法。每個節點要麼選要麼不選,和大多數選不選動歸一樣,來個dp[i][2],0表示不選,1表示不選,那我們
Time of Update: 2018-12-03
題目連結: http://acm.hdu.edu.cn/showproblem.php?pid=4006題目大意:給定n個操作,操作分兩種,插入和查詢第k大的數。n<=1000000解題思路:因為本題沒有刪除操作,所以變得特別簡單,只需要維護一個大小為k的小頂堆即可。 但是如果有刪除操作,就變地複雜了,所以用SBT寫了這道題,怒寫2遍,明天晚上黃金十點半再寫三遍,測模版的沒什麼好說的。測試資料:8 3I 1I 2I 3QI 5QI 4QC艸代碼:#include
Time of Update: 2018-12-03
Girls and Boys Time Limit : 20000/10000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 2 Accepted Submission(s) : 1Font: {ProFont('Times New Roman')}">Times New Roman | {ProFont('Verdana')}">Verdana |
Time of Update: 2018-12-03
題目:buct1711方法:dfs思想:用dfs找出所有可能的排列,並判讀該排列是否是錯位排序序列,若是就直接輸出便可。代碼:(1)#include <iostream>using namespace std;int n,a[10],visited[10];void dfs(int t){int i,tmp;if(t>n){for(i=1;i<=n;i++) if(a[i]==i)break; if(i>n) { for(i=1;i<=n;i++)
Time of Update: 2018-12-03
題目連結:hdu1078 代碼:dfs // each time he can run at most k locations to get into the hole before being caught by Top Killer.//Given n, k, and the number of blocks of cheese at each grid location,//compute the maximum amount of cheese FatMouse can eat
Time of Update: 2018-12-03
題目:tzc2731方法:bfs代碼:#include <iostream>#include <queue>using namespace std;struct node{int n,num;};int n,m;bool g[1005][1005],visited[1005];int s,e;void bfs(){queue <node> q;node pre,tmp;pre.n=s;pre.num=0;q.push(pre);while(!q.empty()
Time of Update: 2018-12-03
題目連結:tzc1100方法:貪心 思想:注意本題是典型的部分背包問題,而不是0-1背包問題。如果他有時間,可以將某份卷子做部分答案。可以按價值比從大到小排序,然後從第頭開始,如果這個的時間小於剩餘時間就將其價值加上,否則加上相應的部分價值,跳出迴圈即可。代碼:#include <iostream>#include <algorithm>using namespace std;struct node{ double x,y; }; bool cmp(node
Time of Update: 2018-12-03
題目連結:zjut1381 pku3356方法:動態規劃思想:源串的最後一個字元要麼直接替換成目標串的最後一個字元(如果本來就相等則不必操作),要麼在源串的最後插入一個字元,要麼刪除源串的最後一個字元。只要算出前面的這些情況,從中選出最小的一個就是兩個字串的編輯距離。從而,有dp[i][j]=min(dp[i-1][j-1]+(s[i-1]==t[j-1]?0:1),dp[i-1][j]+1),dp[i][j-1]+1); ——《挑戰編程》劉汝佳譯 的第207頁(11章
Time of Update: 2018-12-03
題目:buct1766 pku1270方法:dfs思想:利用搜尋或next_permutation產生下一個排列,然後判斷該排列是否滿足要求,如果滿足要求輸出即可。代碼:#include <iostream>#include <algorithm>#include <cstring>using namespace std;char var[50],t[50];char constraint[105][2];bool visited[50];int n,m,
Time of Update: 2018-12-03
題目:hdu1002 總結:本題之所以會WA幾次,是由於沒有把 system("pause"); 刪除,這是應該注意的地方。雖然杭電等網站支援system, 但是程式會運行到這句話,就會出現wrong answer,因此,一般要把這句話刪除再提交。 代碼: //You may assume the length of each integer will not exceed 1000.#include <iostream>#include <string>using
Time of Update: 2018-12-03
題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=4003題目大意:給定一棵n個節點的樹,遍曆每條數邊都需要費用cost,現在給定k個機器人,要求用這個k個機器人遍曆整棵樹,使得經過的費用和最小,n<=10000.解題思路:樹形DP+分組背包,本題的分組背包不是一般性地至多選擇一個物品而是必須選一個,且只能選一個,具體的稍後分析。這題想了挺久的,最開始想的是貪心解法,如果k為1,那麼只要找出從葉子到根費用和最大的那條路徑就好,拓展開來想找出前k大
Time of Update: 2018-12-03
題目:hdu1019 題意:求m個資料的最小公倍數 代碼: /*如果資料還大些,可用__int64。// All results will lie in the range of a 32-bit integer//ans=ans/gcd(ans,a)*a;這句話是要特別注意的,否則會造成資料溢出,而WA。*/#include <stdio.h> long gcd(long a,long b){if(b==0)return a;return gcd(b,a%b);}int main(
Time of Update: 2018-12-03
題目連結:hdu1176 思路:/*動態規劃 狀態表示:dp[i,j]為j秒時在i位置的最大值狀態轉移:i=0 dp[0][j] += Max(dp[0][j+1], dp[1][j+1]); i=10 dp[10][j] += Max(dp[10][j+1], dp[9][j+1]); i=1-9 dp[i][j] += Max(dp[i][j+1], dp[i+1][j+1], dp[i-1][j+1]); 0<=j<=
Time of Update: 2018-12-03
**********************************高精度加,減,乘,除,模數,模板**********************************/#include <iostream>#include <string>using namespace std;inline int compare(string str1, string str2){ if(str1.size() > str2.size())