上一页 1 ··· 26 27 28 29 30 31 32 33 34 ··· 47 下一页

2012年5月29日

摘要: O(nlog(n))的算法,网上讲解有很多,我就不在这里献丑了,直接上模板该模板计算从1到n的LIS,p[]为存放数列的数组最长上升子序列View Code int LIS(int n){ int l,r,m,i,tail = 0; for ( dp[ ++ tail ] = p[ 1 ... 阅读全文
posted @ 2012-05-29 12:28 LegendaryAC 阅读(357) 评论(0) 推荐(0) 编辑
 
摘要: 今天起决定总结自己做题写出来的遇到的找到的各种模板,先从输入挂开始啦有的题目需要大规模输入,很多情况用cin超时,用scanf就能过,因为scanf的速度远远快于cin。但是比scanf还要nb的输入是getchar(),这个读入速度极快,输入挂就是基于这点写的。整数View Code inline bool scan_d(int &num) { char in;bool IsN=false; in=getchar(); if(in==EOF) return false; while(in!='-'&&(in<'0'||in> 阅读全文
posted @ 2012-05-29 12:22 LegendaryAC 阅读(2867) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1677这道题纠结了N个小时,因为原来找的模板里少了两个等号。。。结果就是错在了我一直觉得不会错的LIS里,让我认清了上升和非降的区别?下降数列的个数等于LIS,和导弹拦截那道题基本一致ps:连着三道LIS看排名都进了前三,好开心~View Code #include <iostream>#include <algorithm>using namespace std ;int dp[10001],p[20001];typedef struct L{ int w,h;}L;L kk[200 阅读全文
posted @ 2012-05-29 12:07 LegendaryAC 阅读(457) 评论(0) 推荐(0) 编辑

2012年5月28日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1950和上一题基本一样,二分dp求LISps:排名居然刷到第一了,原来从来没有遇到呢,好开心~View Code #include <iostream>using namespace std ;int dp[10001],p[40001];int LIS(int n){ int l,r,m,i,tail = 0; for ( dp[ ++ tail ] = p[ 1 ],i = 2 ; i <= n ; ++ i ) { if ( dp[ tail ] <= p[ i ] )... 阅读全文
posted @ 2012-05-28 21:37 LegendaryAC 阅读(185) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1025题目有一定迷惑性,实际就是求LIS,我原来掌握的朴实的O(n^2)算法果断超时,新学了一种二分dp O(nlog(n))的算法,直接上模板了,还要多多体会啊View Code #include <iostream>using namespace std ;int dp[10001],p[50001];int LIS(int n){ int l,r,m,i,tail = 0; for ( dp[ ++ tail ] = p[ 1 ],i = 2 ; i <= n ; ++ i ) { . 阅读全文
posted @ 2012-05-28 21:29 LegendaryAC 阅读(114) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1316大数,斐波那契数列View Code import java.io.*;import java.math.*;import java.util.*;import java.text.*;public class Main{ public static void main(String[]args) { Scanner cin=new Scanner (new BufferedInputStream(System.in)); BigInteger a,b; ... 阅读全文
posted @ 2012-05-28 15:45 LegendaryAC 阅读(179) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1394求最小逆序数,逆序数的树状数组求法昨天学会了,今天这题开始用个无脑O(n*n*log(n))的方法,果断超时。其实逆序数只用求一边,每移动一次数列,逆序数增加num[i]-1个,对应减少n-num[i]个,递推即可。View Code #include <stdio.h>#include <stdlib.h> #include <string.h>int n;int tree[5001],num[5001];int lowbit(int i){ return i&am 阅读全文
posted @ 2012-05-28 15:00 LegendaryAC 阅读(152) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1016经典问题,素数环。直接回溯即可。View Code #include <stdio.h>#include <string.h>int n;int a[30];int prime[100],vis[30];void dfs(int cur){ if(cur==n && prime[a[0]+a[n-1]]==0) { printf("%d",a[0]); for(int i=1;i<n;i++) printf(" %d" 阅读全文
posted @ 2012-05-28 12:37 LegendaryAC 阅读(157) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2689树状数组求逆序数,原来一直没搞明白,今天看了一遍文章讲的很清楚,下面把有关内容粘过来:对于小数据,可以直接插入树状数组,对于大数据,则需要离散化,所谓离散化,就是将100 200 300 400 500 ---> 1 2 3 4 5这里主要利用树状数组解决计数问题。首先按顺序把序列a[i]每个数插入到树状数组中,插入的内容是1,表示放了一个数到树状数组中。然后使用sum操作获取当前比a[i]小的数,那么当前i - sum则表示当前比a[i]大的数,如此反复直到所有数都统计完,比如4 3 1 2 i 阅读全文
posted @ 2012-05-28 01:24 LegendaryAC 阅读(468) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2154无聊题。。。View Code #include <stdio.h>#include <stdlib.h> #include <string.h>const int mod=10000;int a[1001],b[1001],c[1001];int main(){ int n; while(scanf("%d",&n),n) { a[0]=1;b[0]=c[0]=0; for(int i=1;i<=n;i++) { a[i... 阅读全文
posted @ 2012-05-28 00:50 LegendaryAC 阅读(244) 评论(0) 推荐(0) 编辑
上一页 1 ··· 26 27 28 29 30 31 32 33 34 ··· 47 下一页