自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(86)
  • 资源 (1)
  • 收藏
  • 关注

原创 hdu 3486 Interviewe 【RMQ】

不满足单调性,所以二分解法不正确(虽然可以过OJ),#include#includeusing namespace std;const int maxn=200000+10;int dp[maxn][20],mylog[maxn],n;long long k;void read(int &d){ char ch; while(ch=getchar(),ch57

2012-02-10 21:05:50 1346 1

原创 hdu 3524 Perfect Squares【打表、除法取余、快速幂】

先打表,找规律#include#includeusing namespace std;int main(){ setmyset; for(long long i=1;i<20;i++,cout<<endl) { myset.clear(); for(long long j=0;j<1000000;j++)

2012-02-10 17:24:36 1144

原创 POJ 2154 Color 【polya+dfs】

看来有必要变得更加强大啊......... 141MS#include#include#includeusing namespace std;const int maxn=1<<15;vector >v;int vis[maxn],prime[maxn];int n,mod,cnt=0;void init(){ for(int i=2;i<maxn;i++)

2012-02-07 01:51:47 607

原创 POJ 3211 Washing Clothes【01背包+STL】

洗每种衣服时间dp[sum[i]-dp[sum[i]>>1];#include#include#include#includeusing namespace std;int dp[1<<17];int main(){ int n,m;cin.sync_with_stdio(false); string str; while(cin>>n>>m&&m&&n)

2012-02-06 14:46:29 598

原创 poj 2977 Box walking

#includeusing namespace std;int sqr(int x){ return x*x;}int main(){ int a,b,c,x,y,z,ans; while(cin>>a>>b>>c>>x>>y>>z&&!(a==0&&b==0&&c==0&&x==0&&y==0&&z==0)) { if(x==0||y=

2012-02-06 11:53:57 934

原创 POJ 3080 Blue Jeans【stl】

#include#includeusing namespace std;int main(){ string s[20],ans,com; int t,n; cin>>t; while(t--) { ans.clear(); cin>>n; for(int i=0;i>s[i]; for

2012-02-06 10:02:46 851

原创 poj 2002 Squares【HASH】POJ最快

先排序,然后枚举任意两点(x1,y1)(x2,y2),则如果存在点(x1+y1-y2,y1-x1+x2)(x2+y1-y2,y2-x1+x2)则它们能构成一个正方形157MS#include#include#include#includeusing namespace std;const int maxn=10000+10;struct node{ int a,b,c

2012-02-05 21:34:27 842

原创 poj 2002 Squares 【stl二分】

764K 1375MS#include#include#includeusing namespace std;const int maxn=10000;paira[maxn];int main(){ int n; while(scanf("%d",&n)&&n) { for(int i=0;i<n;i++) scanf("%d%d",&a[i

2012-02-05 21:28:39 647

原创 poj 2503 Babelfish【trie】

trie:141MS#includeconst int maxn=100000+10;const int tk=26,tb=97;int triecnt=1,bufcnt=0,tree[maxn<<2][tk+1];char buf[maxn<<1][12];int search(char *s){ for(int rt=0;rt=tree[rt][*s-tb];)

2012-02-05 00:27:35 686

原创 poj 2503 Babelfish 【hash】

HASH:141MS#include#include#define th(a) this->a=a;const int maxn=100000+10;const int prime=25013;struct Hash{ char *s1,*s2; Hash *nxt;}hashpool[maxn];Hash *head[prime+1],*ph;char bu

2012-02-04 23:54:09 762

原创 poj 3349 Snowflake Snow Snowflakes【HASH】/【最小表示】

发现最小表示+sort好像还快一点点HASH#include#include#includeusing namespace std;const int maxn=9997;struct node{ int a[6],sum;};vector v[maxn];bool cmp(node b,node c){ if(b.sum!=c.sum) retu

2012-02-04 19:11:22 625

原创 poj 1840 Eqs 【hash】

#includeusing namespace std;const int maxn=50*50*50*50;short hash[maxn*6+10];int main(){ int a,b,c,d,e,ans=0; cin>>a>>b>>c>>d>>e; for(int i=-50;i<=50;i++) if(i) f

2012-02-04 15:24:27 488

原创 hdu 3415 Max Sum of Max-K-sub-sequence【单调队列】

#include#includeusing namespace std;const int maxn=100000+10;int sum[maxn<<1],que[maxn<<1];void read(int &d){ char ch;bool flag=0; while(ch=getchar(),(ch>'9'||ch<'0')&&ch!='-'); ch==

2012-02-04 14:26:17 546

原创 poj 1200 Crazy Search【hash】

#includeusing namespace std;const int maxn=1000000+10;char s[maxn];bool hash[maxn];int vis[150];int main(){ int n,nc,cnt=0,tmp,sum=0,ans=0,mod=1; cin.sync_with_stdio(false); cin>>n>

2012-02-04 14:23:02 640

原创 hdu 3549 Enumerate the Triangles

n^3暴力过了#include#include#includeusing namespace std;struct point{ double x,y;}p[1001];inline double dis(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int ma

2012-02-02 20:06:48 484

原创 hdu 3549 Flow Problem【最大流】

直接模板#includeusing namespace std;const int maxn=20;const int inf=0x3f3f3f3f;struct EK{ int cap[maxn][maxn]; int flow[maxn][maxn]; int n; void init(int n) { this->n=n

2012-02-02 20:03:18 529

原创 hdu 3547 DIY Cube【polya】

ans=17*x^2+6*x^4+x^8#include#include#includeusing namespace std;const int base=10000;const int width=4;const int N=1300;char s[1000];struct bint{ int ln,v[N]; bint(int r=0) {

2012-02-02 20:01:00 875

原创 hdu 3546 Calculator

若c=b,则之前的C不要求,直到遇到更前面有a=c或a*=c或a+=c时,C的值才要计算#include#include#includeusing namespace std;const int base=10000;const int width=4;const int N=1300;struct bint{ int ln,v[N]; bint(int r=0

2012-02-02 19:58:02 772

原创 hdu 3552 I can do it!

sort对X排序, ans=min(x[i]+max(y[i+1]+y[i+2]+……) ) (i=n,n-1,……2,1);以i从大到小的顺序扫描一下o(n);#include#include#includeusing namespace std;struct node{ int x,y;}a[100010];bool cmp(node a,node b){

2012-02-02 19:49:31 693

原创 hdu 3544 Alice's Game 【博弈】

后一人会尽量选前一人切后小的一块切。#includeusing namespace std;int main(){ int t,n,cas=1; long long a,b,x,y; cin>>t; while(t--) { cin>>n; a=b=0; for(int i=0;i<n;i++)

2012-02-02 19:42:19 1256

原创 poj 1159 Palindrome 【DP】

dp[i][j]=dp[i+1][j-1],(s[i]==s[j])  dp[i][j]=min(dp[i+1][j],dp[i][j-1])+1,(s[i]!=s[j])DP+Short数组:Problem: 1159 User: wxfwxf328Memory: 40716K Time: 391MSLanguage: C++ Result: AcceptedSource Code

2012-01-31 17:19:57 503

原创 poj 2181 Jumping Cows 【简单DP】

//dp[i][0]=max(dp[i-1][1]-a[i],dp[i-1][0]);//dp[i][1]=max(dp[i-1][0]+a[i],dp[i-1][1]);#include#includeusing namespace std;const int maxn=200000;int dp[maxn][2],a[maxn];int main(){ int p;

2012-01-28 19:20:58 459

原创 poj 1157 LITTLE SHOP OF FLOWERS 【简单DP】

//dp[i][j]=max(dp[i][j-1]+a[i][j],dp[i][j-1]);#include#includeusing namespace std;const int inf=0x3f3f3f3f;int dp[110][110];int main(){ int n,m,tmp,ans=-inf; scanf("%d%d",&n,&m); f

2012-01-28 18:10:49 517

原创 HDU 1695 GCD 数论好题!

http://acm.hdu.edu.cn/showproblem.php?pid=1695此题思路基本分析出来了,可是写错来WA到不认识家了,果断删了自己代码,参考了别人的代码写的:参考自:http://blog.csdn.net/shiren_bod/article/details/5787722#quote(这个初始化写得好比较好了,一开始自己写用了写了两个函数一个求euler+

2012-01-25 17:16:16 1141

原创 poj 2559 hdu 1506 Largest Rectangle in a Histogram

#includeusing namespace std;const int maxn=100000+10;int a[maxn],b[maxn],c[maxn];//a[i]:高度 b[i]:左边小于a[i]高度的第一个 c[i]:右边小于a[i]高度第一个inline void read(int &d){ char ch; while(ch=getchar(),ch>

2012-01-25 14:38:29 804

原创 hdu 1003 Max Sum【DP】 0MS 248K

//dp[i] = max(dp[i-1]+a[i],dp[i]) = a[i]+dp[i-1]<0?0:dp[i-1];//max=a[i]+max<0?0:max;#includeusing namespace std;inline void read(int &d){ char ch; int flag=1; while(ch=getchar(),ch=='

2012-01-25 13:15:29 818 2

原创 hdu 1231最大连续子序列 【DP】

//dp[i] = max(dp[i-1]+a[i],dp[i]) = a[i]+dp[i-1]<0?0:dp[i-1];//max=a[i]+max<0?0:max;#includeusing namespace std;int a[10010];inline void read(int &d){ char ch; int flag=1; while(ch=g

2012-01-25 12:46:21 631

原创 hdu 1864 最大报销额 【DP】

#include#includeusing namespace std;const int maxn=3000000+10;int dp[maxn],v[100];int main(){ int n,m,cnt; double a[3],q; while(cin>>q>>n&&n) { cnt=0; while(n--)

2012-01-25 12:04:43 714

原创 hdu 2955 Robberies 【dp】 01背包

#includeusing namespace std;const int maxn=10000+10;int m[maxn];double p[maxn],dp[maxn];int main(){ int t,n,sum; double p0; cin.sync_with_stdio(false); cin>>t; while(t--)

2012-01-25 12:03:18 552

原创 poj 2823 Sliding Window 【单调队列】

方案一:STL——DEQUE(C++:TLE  G++:8461MS)#include#includeusing namespace std;const int maxn=1000000+10;int a[maxn],b[maxn],c[maxn];int main(){ ios::sync_with_stdio(false); int i,n,k; d

2012-01-24 21:43:17 832 2

原创 hdu 3400 Line belt【三分嵌套】

二分法作为分治中最常见的方法,适用于单调函数,逼近求解某点的值。但当函数是凸性函数时,二分法就无法适用,这时三分法就可以“大显身手”~~类似于二分的定义Left和Right,mid = (Left + Right) / 2,midmid = (mid + Right) / 2; 如果mid靠近极值点,则Right = midmid;否则(即midmid靠近极值点),则Left = mid;

2012-01-24 17:08:34 1144 3

转载 母函数(Generating function)详解【转自www.wutianqi.com】

原文地址:http://www.wutianqi.com/?p=596最近更新:2011.4.31.鉴于文章图片和排版的问题,对文章进行了重新编辑。2.看见网上很多朋友在转载时不尊重别人的劳动成果,任意删除文章里关于作者的信息,希望大家在转载时保留文章所有信息,遵守版权规定。前段时间写了一篇《背包之01背包、完全背包、多重背包详解》,看到支持的人很多,我不是大牛

2012-01-23 22:12:42 724

原创 hdu 1811 rank of tetras 拓扑排序+并查集

这题写了几天了,好几次写了一半又删了的,发现拓扑还是用queue好啊1.3种结果的优先关系conflict>uncertain>ok,只要是conflict就不是看后两者了,如果不是只有判了是uncertain就不看是否ok了,用solve()函数返回结果的情况2.q.size()>1,同时多个点入度为0,uncertain.(要=判断了conflict才确定)   入q次数与n'不等则

2012-01-23 13:53:16 733

原创 hdu 3343 Legal or Not 拓扑排序(容易题)

#include#includeusing namespace std;const int maxn=100+5;int e[maxn];vectorv[maxn];void toposort(vector v[],const int n){ int flag=1,cnt=0; while(flag) { flag=0; for

2012-01-21 23:12:36 878

原创 hdu 3398 String 数论,catalon的一般形式(两次改进,比最初AC快了两倍)【完整版】

好难的题目啊,是cantalon数的一般情况啊,公式为c(a+b,b)-c(a+b,b-1),一开始想从cantalon推这一题,白浪费了一个小时,又是打了m,n的表和组合数的表,才推了这公式写完提交后无限WA,直到练习赛时间过了才想起来是我求的com(a+b, b)-com(a+b,b-1)可能为负值,因为a>b不代表a%p>b%p,即(a-b)%p = ((a%p-b%p)+p)%p而

2012-01-21 20:14:56 3015 1

原创 HDU 3307 Description has only two Sentences 数论

Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 199    Accepted Submission(s): 9Problem Descrip

2012-01-21 19:59:02 1117

原创 HDU 3314 Trouble with Election! 并查集

这题想通了就好做了,只有投了自己的人才可能是最后的WINNER,找符合的人中最大值是不是唯一#includeusing namespace std;const int maxn=100000+10;int p[maxn],r[maxn],cnt[maxn];void make(){ memset(r,0,sizeof(r)); memset(p,255,sizeof(

2012-01-21 19:29:42 636

原创 hdu 3306 Another kind of Fibonacci

As we all known , the Fibonacci series : F(0) = 1, F(1) = 1, F(N) = F(N - 1) + F(N - 2) (N >= 2).Now we define another kind of Fibonacci : A(0) = 1 , A(1) = 1 , A(N) = X * A(N - 1) + Y * A(N - 2) (N >

2012-01-21 19:20:32 565

原创 求质数表 素数筛求素数 效率比较 数论相关

第一个是平时最常用的基本写法(还有一种写法是for(j=i*2;j第二个是以i*i为起点开始筛的,要注意浮点溢出!第三个不太好简洁地说清楚程序中途分别输出每次计算了的prime[500000],从而为了验证计算结果的正确性的#include#includeusing namespace std;const int N= 40000000;int prime[N],cnt

2012-01-21 04:17:15 692

原创 hdu 2647 Reward 拓扑排序

http://acm.hdu.edu.cn/showproblem.php?pid=2647#include#include#includeusing namespace std;const int maxn=10000+5;paire[maxn];//first:入度 second:工资(最低为0)void toposort(vector v[],const int n){

2012-01-21 01:38:59 782

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除