自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 POJ 3468 A Simple Problem with Integers【线段树】

#include#includeusing namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mid (l+r)>>1typedef long long ll;const int maxn=100000+10;ll sum[maxn<<2],add[maxn<<2];inline voi

2012-02-24 21:37:58 520

原创 HDU 3579 Hello Kiki【中国剩余】

#includeusing namespace std;typedef long long ll;ll ext_gcd(ll a,ll b,ll &x,ll &y){ if(b==0){x=1;y=0;return a;} ll d=ext_gcd(b,a%b,x,y),t; t=x;x=y;y=t-a/b*y; return d;}inline ll

2012-02-24 20:25:01 923

原创 poj 1365 Prime Land 【简单数论】

#include#include#include#includeusing namespace std;bool not_prime[40000];vectorprime,ans;int main(){ for(int i=2;i<40000;i++) if(!not_prime[i]) { prime.push_ba

2012-02-24 20:22:25 844

原创 usaco 2.1.4 Subset Sums 【母函数】

(1+x)*(1+x^2)*(1+x^3)*……*x^n   则 x^(n*(n+1)/2) 的系数一半为ans/* ID: w.x.f.g1 PROG: subset LANG: C++*/#include#include#includeusing namespace std;typedef long long ll;ll c1[400],c2[400],c3[400]

2012-02-21 11:39:54 603

原创 poj2774 Long Long Message && hdu 1403 Longest Common Substring 最长公共字串【后缀数组(倍增)】

参考自2009年国家集训队论文《后缀数组——处理字符串的有力工具》(罗穗骞)将串a与串b连接后用后缀数组求最大height#include#includeusing namespace std;const int maxn=200000+10;int sa[maxn],rank[maxn],height[maxn],num[maxn];int wa[maxn],wb[max

2012-02-17 21:32:29 1371 1

原创 usaco 1.4.2 Packing Rectangles

图上描绘的就是所有的基本摆放方法即4的全排列种方法+交换任意x,y=所有的摆放方法/*ID: w.x.f.g1PROG: packrecLANG: C++*/#include#include#includeusing namespace std;#define forn(a,n) for(int i=a;i<n;i++)#define init() t

2012-02-16 10:55:19 781

原创 HDU 3560 Graph’s Cycle Component 【并查集】

并查集分组,deg必需为2才是circle#include#includeusing namespace std;const int maxn=100000+10;int p[maxn],r[maxn],deg[maxn];bool is_circle[maxn];void init(int n){ memset(p,-1,n<<2); memset(r,0,n<

2012-02-13 22:13:18 1227 1

原创 HDU 3561 How many times 【计算几何】

判断任两圆的交点和每个圆的圆心即可#include#include#includeusing namespace std;#define eps 1e-8const int maxn=105;struct point{ double x,y;};struct circle{ point p; double r;}c[maxn];vectorv;

2012-02-13 22:07:43 838

原创 hdu 3555 Bomb【数位DP】

第一次接触数位DP#includeusing namespace std;long long dp[20][3]={0,1,0},d[20][3];int main(){ for(int i=1;i<20;i++) { dp[i][0]=10*dp[i-1][0]+dp[i-1][2];//含49 dp[i][1]=9*dp[i-1][1

2012-02-13 22:03:32 1008

原创 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 1333 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 1131

原创 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 595

原创 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 583

原创 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 920

原创 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 839

原创 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 778

原创 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 632

原创 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 675

原创 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 751

原创 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 610

原创 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 473

原创 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 532

原创 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 630

原创 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 470

原创 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 522

原创 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 858

原创 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 753

原创 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 683

原创 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 1243

浙江大学ACM模板

完整版的浙江大学ACM模板,PDF原版,很好用的

2012-01-21

空空如也

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

TA关注的人

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