01 2014 档案

ZOJ 3261 Connections in Galaxy War 并查集
摘要:将操作序列反向,用并查集维护集合里最强的星球。--------------const int maxn=11000;const int maxm=22000;const int maxq=55000;int n,m,Q;int p[maxn];int a[maxn];int id[maxn];int pa[maxn];void makeset(int n){ for (int i=0;ia[y]){ a[y]=a[x]; id[y]=id[x]; } else if (a[y]==a[x]&&id[x]ans;set... 阅读全文

posted @ 2014-01-14 22:26 电子幼体 阅读(145) 评论(0) 推荐(0)

SGU 467 Chessmaster 几何
摘要:------------------int n;int main(){ int cas=0; while (~scanf("%d",&n)){ int ans=0; if (n==0) ans=0; else if (n<=78) ans=1; else if (n<=95) ans=2; else if (n<=99) ans=3; else ans=4; printf("Case #%d: %d\n",++cas,ans); } return 0;}------------------ 阅读全文

posted @ 2014-01-13 20:40 电子幼体 阅读(184) 评论(0) 推荐(0)

POJ 2784 Buy or Build 最小生成树
摘要:枚举方案后做最小生成树。------------const int maxn=1100;const int maxm=10000;int n,q;vectorg[10];int c[10];struct Point{ int x,y; int getValueTo(Point p){ return (p.x-x)*(p.x-x)+(p.y-y)*(p.y-y); }}p[maxn];struct EDGE{ int u,v,d; bool operator<(const EDGE& rhs) const{ return d<rhs.d;... 阅读全文

posted @ 2014-01-13 20:39 电子幼体 阅读(209) 评论(0) 推荐(0)

URAL 1023 Buttons 博弈
摘要:当K是L+1的倍数时,先手必败。又因为L>=2,特殊考虑2*p的数据。--------#include #include using namespace std;int main(){ int K,i,L; while (cin>>K){ for (i=3;i4) L=K/2-1; else L=K-1; cout<<L<<endl; } return 0;}-------- 阅读全文

posted @ 2014-01-13 20:37 电子幼体 阅读(116) 评论(0) 推荐(0)

ZOJ 3149 Breadtree DP
摘要:--------------------const int maxn=100000;const int maxm=10000;const LL LIM=1234567890LL;LL n,k;LL f[maxn];LL sum[maxn];int main(){ while (cin>>n>>k){ if (n==0) break; if (k==0) coutLIM) break; } cout<<ans<<endl; } } return 0;}-------------------- 阅读全文

posted @ 2014-01-12 22:30 电子幼体 阅读(143) 评论(0) 推荐(0)

ZOJ 3279 Ants 二分树状数组
摘要:----------const int maxn=110000;const int maxm=10000;int n,m;struct BIT{ int n; int tree[maxn]; void init(int n){ this->n=n; memset(tree,0,sizeof(tree)); } int lowbit(int x){ return x&(-x); } void add(int x,int val){ for (int i=x;i0;i-=lowbit(i)) ret+... 阅读全文

posted @ 2014-01-12 20:38 电子幼体 阅读(131) 评论(0) 推荐(0)

URAL 1039 Anniversary Party 树形dp
摘要:-----------const int maxn=10000;const int maxm=110000;int n;struct EdgeNode{ int to,next;}edges[maxm];int head[maxn],edge;void init(){ memset(head,-1,sizeof(head)); edge=0;}void addedge(int u,int v){ edges[edge].to=v,edges[edge].next=head[u],head[u]=edge++;}int a[maxn];int f[maxn][2];int... 阅读全文

posted @ 2014-01-12 18:37 电子幼体 阅读(130) 评论(0) 推荐(0)

ZOJ 3278 8G Island 二分+二分
摘要:第K大,不是第K小啊 (╯‵□′)╯︵┻━┻----------int n,m;LL K;LL a[maxn],b[maxn];bool C(LL x){ LL res=0; for (int i=1;i=x){ ans=mid; l=mid+1; } else r=mid-1; } res+=ans; } return res>=K;}int main(){ while (cin>>n>>m>>K){ for (int... 阅读全文

posted @ 2014-01-12 17:42 电子幼体 阅读(127) 评论(0) 推荐(0)

POJ 2785 4 Values whose Sum is 0 二分
摘要:---------------const int maxn=4100;const int maxm=10000;int n,m;int a[4][maxn];int b[maxn*maxn];int main(){ while (~scanf("%d",&n)){ for (int i=0;i<n;i++){ for (int k=0;k<4;k++){ scanf("%d",&a[k][i]); } } for (int i=0;i<n;i++){ for... 阅读全文

posted @ 2014-01-11 23:05 电子幼体 阅读(156) 评论(0) 推荐(0)

POJ 3063 Sherlock Holmes 随机化
摘要:----------------int n,m;int w[maxn],b[maxn];int s1[maxn],s2[maxn];int w1,b1,w2,b2;double ans,mo;bool flag;void work(int x,int y) { w1=w1-w[s1[x]]+w[s2[y]]; w2=w2-w[s2[y]]+w[s1[x]]; b1=b1-b[s1[x]]+b[s2[y]]; b2=b2-b[s2[y]]+b[s1[x]]; swap(s1[x],s2[y]);}void cal() { if (w1>b1&&w2>b2) {... 阅读全文

posted @ 2014-01-11 21:28 电子幼体 阅读(192) 评论(0) 推荐(0)

hdu 4080 Stammering Aliens 二分 hash
摘要:POJ 3882 TLE 需后缀数组------------const int SEED = 13331;const int MAX_N = 50000 + 10;char s[MAX_N];struct HASH{ ULL H[MAX_N]; ULL XL[MAX_N]; int len; HASH(){} void build(char *s){ len=strlen(s); H[len]=0; XL[0]=1; for (int i=len-1;i>=0;i--){ H[i]=H[... 阅读全文

posted @ 2014-01-11 21:26 电子幼体 阅读(264) 评论(0) 推荐(0)

POJ 3106 Flip and Turn 模拟 分析
摘要:--------const int maxn=400;const int maxm=200000;int n,m;char a[maxn][maxn];char b[maxn][maxn];int stk[10];int cnt;char s[maxm];char cd[7][3]={"1","CX","V","BY","2","AZ","H"};char sp[7][8]={"1","1H","1H1&q 阅读全文

posted @ 2014-01-10 00:27 电子幼体 阅读(141) 评论(0) 推荐(0)

UVA 10635 Prince and Princess DP LIS
摘要:--------int n;int a1[111111];int a2[111111];int c[111111];int a[111111];int g[111111];int d[111111];int N,p,q;int main(){ int T; scanf("%d",&T); for (int cas=1;cas<=T;cas++) { scanf("%d%d%d",&N,&p,&q); memset(c,0,sizeof(c)); memset(g,0,sizeof(g)); n=0; ... 阅读全文

posted @ 2014-01-10 00:26 电子幼体 阅读(115) 评论(0) 推荐(0)

URAL 1098 Questions 约瑟夫环
摘要:--------int n;int f[maxn];char s[maxn];int main(){ int n=0; while (gets(s+n)){ n=strlen(s); } s[n]=0; f[0]=0; for (int i=1;i<=n;i++) f[i]=(f[i-1]+1999)%i; if (s[f[n]]=='?') printf("Yes\n"); else if (s[f[n]]==' ') printf("No\n"); else printf("No comments\n& 阅读全文

posted @ 2014-01-09 00:54 电子幼体 阅读(120) 评论(0) 推荐(0)

POJ 2786 Keep the Customer Satisfied 优先队列
摘要:----------const int maxn=900000;const int maxm=10000;int n;struct Dat{ int v,lim; const bool operatorque;int main(){ while (~scanf("%d",&n)){ for (int i=0;ia[i].lim){ Dat top=que.top(); que.pop(); sum-=top.v; ans++; ... 阅读全文

posted @ 2014-01-08 23:01 电子幼体 阅读(149) 评论(0) 推荐(0)

UVA 1335 Beijing Guards 二分贪心
摘要:--------const int maxn=110000;const int maxm=10000;int n;int a[maxn];int lb[maxn],rb[maxn];bool C(int x){ lb[0]=a[0]; rb[0]=0; for (int i=1;ia[0]||rb[i]+rb[i-1]>x-a[0]) return false; if (lb[i]+rb[i]>x) return false; if (lb[i]>1; if (C(mid)){ ans=mid; ... 阅读全文

posted @ 2014-01-08 01:40 电子幼体 阅读(190) 评论(0) 推荐(0)

POJ 3169 Layout 差分约束系统
摘要:d_x d_x d_y = mind --> d_x que; int dis[maxn]; void addedge(int u,int v,int c){ edges[edge].w=c,edges[edge].to=v,edges[edge].next=head[u],head[u]=edge++; } void init(int n){ memset(head,-1,sizeof(head)); edge=0; this->n=n; } bool spfa(int s){ in... 阅读全文

posted @ 2014-01-07 22:56 电子幼体 阅读(123) 评论(0) 推荐(0)

ZOJ 2334 Monkey King 可并堆左偏树
摘要:----------int n,m;class LeftistTree{private: int tot,v[maxn],l[maxn],r[maxn],d[maxn];public: int merge(int x,int y){ if (!x) return y; if (!y) return x; if (v[x]<v[y]) swap(x,y); r[x]=merge(r[x],y); if (d[l[x]]<d[r[x]]) swap(l[x],r[x]); d[x]=d[r[x]]+1;... 阅读全文

posted @ 2014-01-07 22:10 电子幼体 阅读(150) 评论(0) 推荐(0)

ZOJ 2112 Dynamic Rankings 线段树套平衡树
摘要:------------const int N=60010;const int M=10010;class SegmentTree_Treap{private: struct Treap{ int key,fix,cnt,size,ch[2]; }T[N*15]; int tree[Nt) return select(T[x].ch[0],t); return T[x].cnt+T[T[x].ch[0]].size+select(T[x].ch[1],t); }public: void treeins(int l,int r,int i... 阅读全文

posted @ 2014-01-07 00:09 电子幼体 阅读(127) 评论(0) 推荐(0)

POJ 2796 Feel Good 并查集
摘要:答案为0时要输出一个合理的区间...这是个坑.-----------------------const int maxn=110000;const int maxm=10000;int n;int a[maxn];struct Dat{ int v; int idx;};bool cmp(const Dat& a,const Dat& b){ return a.v>b.v;}Dat b[maxn];int L[maxn],R[maxn],Mis[maxn];int pa[maxn];void makeset(int n){ for (int i=0;i1&& 阅读全文

posted @ 2014-01-06 22:21 电子幼体 阅读(184) 评论(0) 推荐(0)

POJ 2970 The lazy programmer 优先队列
摘要:--------------const double EPS = 1e-7;const int maxn=150000;int dcmp(double a,double b){ if (abs(a-b)b) return 1; else return -1;}struct Dat{ int a,b,d; double c; bool operatorque;int n;Dat a[maxn];int main(){ while (~scanf("%d",&n)){ while (!que.empty()) que.pop(); f... 阅读全文

posted @ 2014-01-06 00:53 电子幼体 阅读(320) 评论(0) 推荐(0)

SGU 180 Inversions 逆序数
摘要:--------------int n;int a[maxn];int b[maxn];struct BIT{ int n; int tree[maxn]; void init(int n){ this->n=n; memset(tree,0,sizeof(tree)); } int lowbit(int x){ return x&(-x); } void add(int x,int val){ for (int i=x;i0;i-=lowbit(i)) ret+=tree[i]; ... 阅读全文

posted @ 2014-01-05 19:38 电子幼体 阅读(149) 评论(0) 推荐(0)

SGU 271 Book Pile 双端队列
摘要:------------int n,m,k;dequeque;vectorans;char cmd[22],c[4];;int bit;int main(){ scanf("%d%d%d",&n,&m,&k); que.clear(); ans.clear(); for (int i=0;ik){ ans.push_back(que.back()); que.pop_back(); } bit=1; for (int i=0;ik){ ans.push_back(que.back()); ... 阅读全文

posted @ 2014-01-05 13:23 电子幼体 阅读(199) 评论(0) 推荐(0)

导航