随笔分类 - ACM
常见算法
摘要:吃土豆时间限制:1000 ms | 内存限制:65535 KB难度:4描述Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled with different qualities beans. ...
阅读全文
摘要:12#include3#include4#include5usingnamespacestd;6#definemax(a,b)a>b?a:b7#defineMAX500058#defineM2005910structgoods{11intc;//重量12intw;//价值13}a[M];1415in...
阅读全文
摘要:2013年4月22日作业题时间限制:3000 ms | 内存限制:65535 KB难度:3描述小白同学这学期有一门课程叫做《数值计算方法》,这是一门有效使用数字计算机求数学问题近似解的方法与过程,以及由相关理论构成的学科……今天他们的Teacher S,给他们出了一道作业题。Teacher S给了他...
阅读全文
摘要:View Code 1#include2#include3#include4usingnamespacestd;5inta[100001],b[100001];67intmain()8{9//freopen("in.txt","r",stdin);10intn;11memset(a,0,sizeof...
阅读全文
摘要:1#include2#include3usingnamespacestd;4#definemax(a,b)a>b?a:b5structgoods{6intv;//价格7intp;//重要程度8intw;//v*p9}a[26];1011intdp[30001];1213intmain()14{15/...
阅读全文
摘要:1#include2#include3usingnamespacestd;4chara[100010];5boolb[100010];6voidfn(intn)7{8memset(b,false,sizeof(b));9if(n==1)cout>t;32while(t--)33{34cin>>n;3...
阅读全文
摘要:1#include2#include3#include4usingnamespacestd;5intJc[13]={0,1};6boolmark[13];7intmain()8{9//freopen("in.txt","r",stdin);10charch;11intk,i,j,s,t;12for(...
阅读全文
摘要:状态迁移方程为:dp[i][j] += dp[i-1][j-k],dp[i][j]表示前i位数字的和为j,假设第i位数字为k,则前i为数字之和则为dp[i-1][j-k];(02usingnamespacestd;3intdp[11][82];4voidfn()5{6inti,j,k;7for(i=...
阅读全文
摘要:1//字典树的应用2#include3#include4#include5#include6#include7usingnamespacestd;89typedefstructphone{10structphone*num[10];11intcount;12}*Ph;1314Phroot;15int...
阅读全文
摘要:守恒法--扩展阅读:http://www.cnblogs.com/dongsheng/archive/2013/03/04/2943206.html#include#includeusingnamespacestd;ints1[1001],s2[1001];intmain(){//freopen("...
阅读全文
摘要:1#include2#include3#include4usingnamespacestd;56typedefstructTri{7intid;8intl;9intw;10Tri():id(0),l(0),w(0){}11}Tri;12131415boolcmp(Tria,Trib)16{17ret...
阅读全文
摘要:1#include2#include3#include4#defineN265chars[11];6intmax;78typedefstructTrie{9Trie*next[N];//含有26个结点指针(a,b,c.......z)10intcount;11}*Node;1213Noderoot;...
阅读全文
摘要:1/*******************************************************2状态转移方程:3s1[i]==s2[j]时,same[i,j]=1;4ans=max(a[i][j]+same[i,j],a[i][j-1],a[i-1][j])56*********...
阅读全文
摘要:1#include2#include3#include4usingnamespacestd;5#definemax(a,b)a>b?a:b6intstack[100010]={-2},len[100010];7intmain()8{9intt,i,w,h,top;10longlongresult;1...
阅读全文
摘要:1中缀式变后缀式23时间限制:1000ms|内存限制:65535KB45难度:367描述人们的日常习惯是把算术表达式写成中缀式,但对于机器来说更“习惯于”后缀式,关于算术表达式的中缀式和后缀式的论述一般的数据结构书都有相关内容可供参看,这里不再赘述,现在你的任务是将中缀式变为后缀式。8输入第一行输入...
阅读全文
摘要:1 //本题的关键是离散化,不然数组的空间不能开那么大,接下来运用树状数组来存储,查找,问题便可迎刃而解 2 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define M 300005 9 10 st...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 #define N 10010 6 int parent[N],in[N]; 7 bool visit[N]; 8 9 int find(int x)10 {11 if(x == pare...
阅读全文
摘要:#include#define N 100005int a[N];void fn(int c){ int p = a[c]; if(p != 0) { fn(p); a[p] = c; }}int main(){// freopen("in.txt","r",stdin); int s,i,n,...
阅读全文
摘要:#include#include#include#include#includeusing namespace std;char c[1005];/*int Is(char c){ if(c=='+' || c=='-' || c=='*' || c=='/') return 1; else r...
阅读全文
摘要:#includevoid fn(int n){int t=n;for(int i=2; i*i<=n; ++i){ if(n%i == 0) t -= t/i;while( ! (n%i))n/=i;}if(n!=1) t = t/n*(n-1); printf("%d\n",t); }int ma...
阅读全文
浙公网安备 33010602011771号