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) 编辑