随笔分类 - ACM刷题
摘要:筛选法求素数~~~~~#include #include #include #include using namespace std;int prim[50000];int main(){ memset(prim,0,sizeof(prim)); int i; for(i=2;im...
阅读全文
摘要:按这题目来就行#include #include #include using namespace std;struct node{ char name[35]; int total_num;};node tree[10001];int main(){ int len=0,num=0; char s...
阅读全文
摘要:rmq的st算法,还有就是从头遍历的小技巧,不然仍然会超时。。。。#include#include#includeusing namespace std;#define max(a,b) (a>b?a:b) #define min(a,b) (a=1;j--) { mx[j][i]=mx[j][i...
阅读全文
摘要:RMQ (Range Minimum/Maximum Query)问题是指:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j #include #include #define max(a,b) (a>b?a:b) #define min(a,b) (a=1;j-...
阅读全文
摘要:水题,我竟然把Yes和No写成了YES和NO。。。。。#include#includeusing namespace std;int frid[105][105];int cloth[105];int n;int r_right;void dfs(int m,int c){ //cout<<m<<e...
阅读全文
摘要:这道题着实让无数人纠结,wa了n次n天,poj的discuss有大量的数据,wa的同学可以试一试。结果我把数据都过了还是wa,后来在discuss的帮助下终于ac了,判断是否有环要最先判断,例如如下的数据:4 4A#include#includeusing namespace std;int map...
阅读全文
摘要:大数,题目有点误解人。。。明明说VeryLongInteger但运算的却不是数字而是文本行#include#includeusing namespace std;char str1[1000005],str2[105];int main(){ scanf("%s",str1); while(scan...
阅读全文
摘要:水题 简单的博弈思想#include#includeusing namespace std;int main(){ int n,k; while(scanf("%d%d",&n,&k),n||k) { int i=n%(k+1); if(i!=1) printf("16\n"); else prin...
阅读全文
摘要:水题,应用简单dp,含i个字符的串的个数等于i-1个字符的串的个数*2(包扩加上0和加上1),再减去最后3个字符是011的情况。#include#includeusing namespace std;double dp[41];int main(){ memset(dp,0,sizeof(dp));...
阅读全文
摘要:copy来的思想,果然自己还很菜啊递归方程式如下(f(i,j)为i个砖头,第一排为j个的摆发):f(i,j)=f(i-j,j+1)+f(i-j,j+2)+...+f(i-j,floor((i-j-1)/2)#include#includeusing namespace std;double p[50...
阅读全文
摘要:水题,做1089太郁闷了所以刷了到水题,代码很笨,基本没有参考价值,只为看一眼快把我折磨死的气球。。。。。。。。。。。#include#includeusing namespace std;char str1[1005],str2[1005];int main(){ while(scanf("%s%...
阅读全文
摘要:我这辈子都会记住这个定理:n元循环群(a)中,元素a^m是(a)的生成元的充要条件是(n,m)=1.哎,郁闷。。。。#include#includeusing namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { i...
阅读全文
摘要:又见0-1背包,长度既是价值也是体积。#include#includeusing namespace std;int dp[100000];int cd[105];int main(){ int cd_sto; while(scanf("%d",&cd_sto)!=EOF) { int n; sca...
阅读全文
摘要:欧拉回路 在加上 并查集判断连通性,把每一个单词当做一个边,话说我一开始当做h路做的。。。。。#include#include#includeusing namespace std;int father[26],rank[26],r[26],c[26],mark[26];int find(int x...
阅读全文
摘要:各种序。。。。。。。。。。。#include#include#includeusing namespace std;void tree(char *s1,char *s2){ if(s1[0]=='\0') return; else if(s1[1]=='\0') { printf("%c",s1[...
阅读全文
摘要:一开始超时,怎么改都超时,后来果断把stl换成纯数组,竟然AC了,莫非stl的操作很费时间吗,不解:之前的超时stl版:#include#include#includeusing namespace std;int mark[10005];int main(){ int n; while(scan...
阅读全文
摘要:给出中根序列和后根序列求路径值最小的叶节点,各种队,各种栈(话说一开始理解错题了,英语不好的悲哀)#include#include#includeusing namespace std;int mmaaxx;int k;void tree(stack s1,stack s2,int m){ if(s...
阅读全文
摘要:先找各阶段的状态,再dp规律是:2*1的不同的数目为2;2*2的不同的数目为7;2*3的不同的数目为8;以下全为8,注意这里说的不同的数目是指2*n中横跨n个格的放法,即不可分割的放法。#include#includeusing namespace std;int dp[101];int main(...
阅读全文
摘要:贪心,弄个2重循环,每次取最优就可以了。#include#include#include#include using namespace std;int a[52];int main(){ int n,k; while(scanf("%d%d",&n,&k)!=EOF) { int i,j; for...
阅读全文
摘要:据说要用dp,不过我用的是BFS,就是从上下左右四个方向压缩,在余下的面积不小于max的情况下一直到压缩出全为一的子阵,然后更新max的值,反复进行这个操作,即一开始的矩阵为:1 1 1 10 0 0 01 1 1 10 0 0 0可以压缩为:0 0 0 0 (去掉第一行)1 1 1 10 0 0 ...
阅读全文

浙公网安备 33010602011771号