这周各种头疼,一直睡觉+发呆,啥子都没干。

就补一下之前的东西。

d1t1小凸玩矩阵

传送门

一开始脑子抽写了最小费用最大流,不知道自己怎么想的。

第k大最小,明显的二分,又是二分图,二分第k大值,把小于它的边权值设为1,大于它的权值设为0跑最大流即可,也可以直接用匈牙利。

  1. //Achen
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<queue>
  9. #include<cmath>
  10. const int N=;
  11. typedef long long LL;
  12. using namespace std;
  13. int s,t,n,m,k,a[N][N],is[N][N],vis[N],pr[N],l=1e9,r=;
  14.  
  15. template<typename T>void read(T &x) {
  16. char ch=getchar(); x=; T f=;
  17. while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
  18. if(ch=='-') f=-,ch=getchar();
  19. for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
  20. }
  21.  
  22. int find(int x) {
  23. for(int i=;i<=m;i++) if(!vis[i]&&is[x][i]) {
  24. vis[i]=;
  25. if(pr[i]==-||find(pr[i])) {
  26. pr[i]=x;
  27. return ;
  28. }
  29. }
  30. return ;
  31. }
  32.  
  33. int ok(int x) {
  34. for(int i=;i<=n;i++)
  35. for(int j=;j<=m;j++) {
  36. if(a[i][j]>x) is[i][j]=;
  37. else is[i][j]=;
  38. }
  39. int rs=;
  40. memset(pr,-,sizeof(pr));
  41. for(int i=;i<=n;i++) {
  42. memset(vis,,sizeof(vis));
  43. rs+=find(i);
  44. }
  45. return rs>n-k;
  46. }
  47.  
  48. int main() {
  49. #ifdef DEBUG
  50. freopen(".in","r",stdin);
  51. freopen(".out","w",stdout);
  52. #endif
  53. read(n); read(m); read(k);
  54. for(int i=;i<=n;i++)
  55. for(int j=;j<=m;j++) {
  56. read(a[i][j]);
  57. l=min(l,a[i][j]);
  58. r=max(r,a[i][j]);
  59. }
  60. int ans=r;
  61. while(l<=r) {
  62. int mid=((l+r)>>);
  63. if(ok(mid)) ans=mid,r=mid-;
  64. else l=mid+;
  65. }
  66. printf("%d\n",ans);
  67. return ;
  68. }

d1t2国旗计划

传送门

先倍长破环为链。

记每个区间的nx,为左端点在这个区间左端点之后,右端点之前的,右端点最靠右的区间。那么每个区间的答案就是一直沿着nx跳直到覆盖的长度超过环长。

找nx,可以先把每个区间拆成左右端点,按pos排序,pos相同先排左端点。从左往右扫,扫到一个左端点就更新当前可以到达的右端点的最右值,扫到一个右端点就更新当前区间的答案。

扫一遍也就可以把第一个区间为起点的答案求出来了,记为k。

那么其他区间的答案肯定是k,k+1或者k-1。

把每个区间的nx设为它的父亲,建出一颗以第2*n个区间为根的树,那么每个区间的答案就是,判断它的第k个、第k-1个,第k+1个父亲到它能不能覆盖整个环长,选最近的父亲更新答案。

这个在dfs过程中把访问到的点都放进栈里就好了。

  1. //Achen
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<queue>
  9. #include<cmath>
  10. const int N=1e6+;
  11. typedef long long LL;
  12. using namespace std;
  13. int n,m,k=1e9+,l[N],r[N],ans[N],cnt,fa[N];
  14.  
  15. template<typename T>void read(T &x) {
  16. char ch=getchar(); x=; T f=;
  17. while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
  18. if(ch=='-') f=-,ch=getchar();
  19. for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
  20. }
  21.  
  22. struct node {
  23. int f,id;
  24. LL pos;
  25. node(){}
  26. node(LL pos,int f,int id):pos(pos),f(f),id(id){}
  27. friend bool operator <(const node &A,const node &B) {
  28. return A.pos<B.pos||(A.pos==B.pos&&A.f<B.f);
  29. }
  30. }p[N];
  31.  
  32. int ecnt,fir[N],nxt[N],to[N];
  33. void add(int u,int v) {
  34. nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v;
  35. }
  36.  
  37. int que[N],top=;
  38. void dfs(int x) {
  39. que[++top]=x;
  40. if(top&&top>=k-) {
  41. if(top>k&&r[que[top-k]]-l[x]>=m) ans[x]=min(ans[x],k+);
  42. if(top>k-&&r[que[top-k+]]-l[x]>=m) ans[x]=min(ans[x],k);
  43. if(top>k-&&r[que[top-k+]]-l[x]>=m) ans[x]=min(ans[x],k-);
  44. }
  45. for(int i=fir[x];i;i=nxt[i])
  46. dfs(to[i]);
  47. top--;
  48. }
  49.  
  50. int main() {
  51. #ifdef DEBUG
  52. freopen(".in","r",stdin);
  53. freopen(".out","w",stdout);
  54. #endif
  55. memset(ans,,sizeof(ans));
  56. read(n); read(m);
  57. for(int i=;i<=n;i++) {
  58. read(l[i]); read(r[i]);
  59. if(r[i]<=l[i]) r[i]+=m;
  60. p[++cnt]=node(l[i],,i);
  61. p[++cnt]=node(r[i],,i);
  62. l[i+n]=l[i]+m; r[i+n]=r[i]+m;
  63. p[++cnt]=node(l[i+n],,i+n);
  64. p[++cnt]=node(r[i+n],,i+n);
  65. }
  66. sort(p+,p+cnt+);
  67. int s=-,now=,mx=,mxid,t,rt;
  68. for(int i=;i<=cnt;i++) {
  69. if(p[i].f==) {
  70. if(s==-) {
  71. s=p[i].id; now=s; t=; mxid=p[i].id;
  72. }
  73. if(r[p[i].id]>mx) mx=r[p[i].id],mxid=p[i].id;
  74. }
  75. else {
  76. if(p[i].id==now) { t++; now=mxid; }
  77. fa[p[i].id]=mxid;
  78. }
  79. if(r[now]-l[s]>=m) k=min(k,t);
  80. }
  81. for(int i=;i<=*n;i++) {
  82. if(fa[i]!=i) add(fa[i],i);
  83. else rt=i;
  84. }
  85. dfs(rt);
  86. for(int i=;i<=n;i++) printf("%d ",ans[i]);
  87. return ;
  88. }

d1t3小凸想跑步

传送门

半平面交的模板题。

把需要的三角形面积小于其他每个三角形的式子列出来,就是一坨半平面的式子,直接半平面交求面积即可。

计算几何,模板打错最为致命。

  1. //Achen
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<queue>
  9. #include<cmath>
  10. typedef long long LL;
  11. typedef double db;
  12. using namespace std;
  13. const int N=3e5+;
  14. const db eps=1e-;
  15. int n,cnt,tot;
  16. db ans;
  17.  
  18. template<typename T>void read(T &x) {
  19. char ch=getchar(); x=; T f=;
  20. while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
  21. if(ch=='-') f=-,ch=getchar();
  22. for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
  23. }
  24.  
  25. struct pt {
  26. db x,y;
  27. pt(){}
  28. pt(db x,db y):x(x),y(y){}
  29. }p[N],T0,T1,T2,T3;
  30.  
  31. pt operator + (pt A,pt B) { return pt(A.x+B.x,A.y+B.y); }
  32. pt operator - (pt A,pt B) { return pt(A.x-B.x,A.y-B.y); }
  33. pt operator * (pt A,db p) { return pt(A.x*p,A.y*p); }
  34. pt operator / (pt A,db p) { return pt(A.x/p,A.y/p); }
  35. db dot(pt A,pt B) { return A.x*B.x+A.y*B.y; }
  36. db cross(pt A,pt B) { return A.x*B.y-A.y*B.x; }
  37. db length(pt A) { return sqrt(dot(A,A)); }
  38. db dcmp(db x) { return (fabs(x)<eps)?:(x<?-:); }
  39.  
  40. struct Line {
  41. pt a,b;
  42. db slop;
  43. friend bool operator <(const Line&A,const Line&B) {
  44. return (A.slop<B.slop)||(A.slop==B.slop&&cross(A.b-A.a,B.b-A.a)<);
  45. }
  46. }L[N],a[N];
  47.  
  48. db get_Area(int n) {
  49. if(n<) return ;
  50. db res=; p[n+]=p[];
  51. for(int i=;i<=n;i++) res+=cross(p[i],p[i+]);
  52. return fabs(res)/2.0;
  53. }
  54.  
  55. pt inter(Line A,Line B) {
  56. pt rs;
  57. db k1=cross(B.b-A.a,A.b-A.a);
  58. db k2=cross(A.b-A.a,B.a-A.a);
  59. db t=k1/(k1+k2);
  60. rs.x=B.b.x+(B.a.x-B.b.x)*t;
  61. rs.y=B.b.y+(B.a.y-B.b.y)*t;
  62. return rs;
  63. }
  64.  
  65. int ck(Line A,Line B,Line P) {
  66. pt t=inter(A,B);
  67. return cross(t-P.a,P.b-P.a)>;
  68. }
  69.  
  70. db solve(int n) {
  71. sort(L+,L+n+);
  72. tot=;
  73. for(int i=;i<=n;i++)
  74. if(i==||L[i].slop!=L[i-].slop) a[++tot]=L[i];
  75. cnt=; int ql=,qr=;
  76. L[++qr]=a[]; L[++qr]=a[];
  77. for(int i=;i<=tot;i++) {
  78. while(qr>ql&&ck(L[qr-],L[qr],a[i])) qr--;
  79. while(qr>ql&&ck(L[ql+],L[ql],a[i])) ql++;
  80. L[++qr]=a[i];
  81. }
  82. while(qr>ql&&ck(L[qr-],L[qr],L[ql])) qr--;
  83. while(qr>ql&&ck(L[ql+],L[ql],L[qr])) ql++;
  84. L[qr+]=L[ql];
  85. for(int i=ql;i<=qr;i++)
  86. p[++cnt]=inter(L[i],L[i+]);
  87. return get_Area(cnt);
  88. }
  89.  
  90. int main() {
  91. #ifdef DEBUG
  92. freopen(".in","r",stdin);
  93. freopen(".out","w",stdout);
  94. #endif
  95. read(n);
  96. for(int i=;i<=n;i++) {
  97. read(p[i].x); read(p[i].y);
  98. }
  99. p[n+]=p[]; ans=get_Area(n);
  100. for(int i=;i<=n;i++) {
  101. L[++cnt].a=p[i]; L[cnt].b=p[i+];
  102. L[cnt].slop=atan2(L[cnt].b.y-L[cnt].a.y,L[cnt].b.x-L[cnt].a.x);
  103. }
  104. T0=p[]; T1=p[];
  105. for(int i=;i<=n;i++) {
  106. T2=p[i]; T3=p[i+];
  107. db a=T0.y-T1.y-T2.y+T3.y;
  108. db b=T1.x-T0.x-T3.x+T2.x;
  109. db c=cross(T2,T3)-cross(T0,T1);
  110. db xx,yy;
  111. if(a==&&b==) continue;
  112. if(b==) { xx=c/a; yy=;}
  113. else if(a==) { xx=; yy=c/b; }
  114. else xx=,yy=(c-a*xx)/b;
  115. L[++cnt].a=pt(xx,yy);
  116.  
  117. if(b==) { xx=c/a; yy=;}
  118. else if(a==) { xx=; yy=c/b; }
  119. else xx=,yy=(c-a*xx)/b;
  120.  
  121. L[cnt].b=pt(xx,yy);
  122.  
  123. if(b==) xx=xx+;
  124. else if(a==) yy=yy+;
  125. else yy=yy+;
  126.  
  127. pt tp=pt(xx,yy);
  128. if(a*xx+b*yy-c<) {
  129. if(cross(L[cnt].b-L[cnt].a,tp-L[cnt].a)<) swap(L[cnt].a,L[cnt].b);
  130. }
  131. else {
  132. if(cross(L[cnt].b-L[cnt].a,tp-L[cnt].a)>) swap(L[cnt].a,L[cnt].b);
  133. }
  134. L[cnt].slop=atan2(L[cnt].b.y-L[cnt].a.y,L[cnt].b.x-L[cnt].a.x);
  135. }
  136. ans=solve(cnt)/ans;
  137. printf("%.4lf\n",ans);
  138. return ;
  139. }
  140. /*
  141. 5
  142. 1 8
  143. 0 7
  144. 0 0
  145. 8 0
  146. 8 8
  147. */

d2t1小凸玩密室

传送门

奥妙重重的树形dp

容易想到最基础的dp,dp[i][j]表示点亮了x的整颗子树,最后一个点亮的是j的方案数。

尝试优化这个dp,对于一个有父亲的x来说,要么是先点亮它的父亲再点它,再点它兄弟,要么是先点它,再点它父亲,再点它兄弟(它兄弟先的两种情况对称)。

也就是要么它要对他父亲负责,要么它要对他父亲的另一个儿子负责。

那么对于每一个叶子节点,要么它要对它的某个祖先负责,要么它要对某个祖先的儿子负责。

g[x][i]表示点亮x后点亮x的第i个祖先需要的最小代价,f[x][i]表示点亮x后点亮x的第i个祖先的另一个儿子的最小代价。

就可以直接转移了 (b表示到父亲的边的权值)

  1. g[x][i]=min(b[lc]*v[lc]+f[lc][0]+g[rc][i+1],b[rc]*v[rc]+f[rc][0]+g[lc][i+1]);
  2. f[x][i]=min(b[lc]*v[lc]+f[lc][0]+f[rc][i+1],b[rc]*v[rc]+f[rc][0]+f[lc][i+1]);

然后再枚举从每个点开始点统计答案即可。

  1. //Achen
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<queue>
  9. #include<cmath>
  10. #define For(i,a,b) for(int i=(a);i<=(b);i++)
  11. #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
  12. const int N=2e5+;
  13. typedef long long LL;
  14. typedef double db;
  15. using namespace std;
  16. int n;
  17. LL v[N],f[N][],g[N][],R[N],ans,b[N];
  18. //f[x][i] 点亮子树x之后点了x的第i个父亲的儿子
  19. //g[x][i] 点亮子树x之后点了x的第i个父亲
  20.  
  21. template<typename T>void read(T &x) {
  22. char ch=getchar(); x=; T f=;
  23. while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
  24. if(ch=='-') f=-,ch=getchar();
  25. for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
  26. }
  27. #define lc x<<1
  28. #define rc (x<<1|1)
  29.  
  30. void dfs(int x) {
  31. R[x]=R[x/]+b[x];
  32. if(lc>n) {
  33. int fa=x/,pr=x;
  34. For(i,,) {
  35. int son=(pr&)?(fa<<):(fa<<|);
  36. g[x][i]=(R[x]-R[fa])*v[fa];
  37. f[x][i]=(R[x]-R[fa]+b[son])*v[son];
  38. pr=fa; fa/=;
  39. }
  40. return;
  41. }
  42. dfs(lc); dfs(rc);
  43. For(i,,) {
  44. if(rc>n) {
  45. g[x][i]=b[lc]*v[lc]+g[lc][i+];
  46. f[x][i]=b[lc]*v[lc]+f[lc][i+];
  47. }
  48. else {
  49. g[x][i]=min(b[lc]*v[lc]+f[lc][]+g[rc][i+],b[rc]*v[rc]+f[rc][]+g[lc][i+]);
  50. f[x][i]=min(b[lc]*v[lc]+f[lc][]+f[rc][i+],b[rc]*v[rc]+f[rc][]+f[lc][i+]);
  51. }
  52. }
  53. }
  54.  
  55. void calc(int x) {
  56. LL tp=g[x][];
  57. int fa=x/,pr=x;
  58. for(;fa;) {
  59. int son=(pr&)?(fa<<):(fa<<|);
  60. tp+=b[son]*v[son]+g[son][];
  61. pr=fa; fa/=;
  62. }
  63. ans=min(ans,tp);
  64. if(lc>n) return;
  65. calc(lc); calc(rc);
  66. }
  67.  
  68. int main() {
  69. #ifdef DEBUG
  70. freopen(".in","r",stdin);
  71. freopen(".out","w",stdout);
  72. #endif
  73. memset(g,/,sizeof(g));
  74. memset(f,/,sizeof(f));
  75. ans=g[][];
  76. read(n);
  77. For(i,,n) read(v[i]);
  78. For(i,,n) read(b[i]);
  79. dfs();
  80. calc();
  81. printf("%lld\n",ans);
  82. return ;
  83. }

d2t2

传送门

没写,就口胡一下。

用一个set存每一段0的区间,每次从一个点开始先暴力修改这个点的值,修改我的set,查完后改回来。

查询的时候就看现在查的在哪个位置,可以把整段区间分成左右两半,小的一半直接找begin或者rbegin即可,大的一半lower_bound ( i+n/2 ) 用左右两个区间更新答案。

需要注意找到的区间若包涵当前查询位置更新的答案为0,还要特判最前最后区间连一起的情况。

d2t3 情报传递

传送门

第一问直接查询lca即可。

第二问,相当于给每个点赋值,询问路径上小于某个值的点的个数。

把赋值操作离线下来排序,查询也离线下来排序,树链剖分即可。

如果你闲的淡疼,也可以写个啥子主席树之类的。

SCOI2015的更多相关文章

  1. bzoj4447[Scoi2015]小凸解密码

    4447: [Scoi2015]小凸解密码 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 150  Solved: 58[Submit][Status ...

  2. BZOJ_4448_[Scoi2015]情报传递_主席树

    BZOJ_4448_[Scoi2015]情报传递_主席树 Description 奈特公司是一个巨大的情报公司,它有着庞大的情报网络.情报网络中共有n名情报员.每名情报员口J-能有 若T名(可能没有) ...

  3. BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配

    BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配 Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个 ...

  4. 「SCOI2015」小凸想跑步 解题报告

    「SCOI2015」小凸想跑步 最开始以为和多边形的重心有关,后来发现多边形的重心没啥好玩的性质 实际上你把面积小于的不等式列出来,发现是一次的,那么就可以半平面交了 Code: #include & ...

  5. 「SCOI2015」国旗计划 解题报告

    「SCOI2015」国旗计划 蛮有趣的一个题 注意到区间互不交错,那么如果我们已经钦定了一个区间,它选择的下一个区间是唯一的,就是和它有交且右端点在最右边的,这个可以单调队列预处理一下 然后往后面跳拿 ...

  6. 「SCOI2015」小凸解密码 解题报告

    「SCOI2015」小凸解密码 题意:给一个环,定义一段连续的极长\(0\)串为\(0\)区间,定义一个位置的离一个\(0\)区间的距离为这个位置离这个区间中\(0\)的距离的最小值,每次询问一个位置 ...

  7. 「SCOI2015」小凸玩矩阵 解题报告

    「SCOI2015」小凸玩矩阵 我好沙茶啊 把点当边连接行和列,在外面二分答案跑图的匹配就行了 我最开始二分方向搞反了,样例没过. 脑袋一抽,这绝壁要费用流,连忙打了个KM 然后wa了,一想这个不是完 ...

  8. 「SCOI2015」小凸玩密室 解题报告

    「SCOI2015」小凸玩密室 虽然有心里在想一些奇奇怪怪的事情的原因,不过还是写太久了.. 不过这个题本身也挺厉害的 注意第一个被点亮的是任意选的,我最开始压根没注意到 \(dp_{i,j}\)代表 ...

  9. [SCOI2015]国旗计划[Wf2014]Surveillance

    [SCOI2015]国旗计划 A国正在开展一项伟大的计划——国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这 项计划需要多名边防战士以接力的形式共同完成,为此,国土安全局已经挑选了N名 ...

  10. loj#2009.「SCOI2015」小凸玩密室

    题目链接 loj#2009. 「SCOI2015」小凸玩密室 题解 树高不会很高<=20 点亮灯泡x,点亮x的一个子树,再点亮x另外的子树, 然后回到x的父节点,点亮父节点之后再点亮父节点的其他 ...

随机推荐

  1. AtCoder ABC 128D equeue

    题目链接:https://atcoder.jp/contests/abc128/tasks/abc128_d 题目大意 有一个双端队列,里面有 N 个整数,你可以进行如下4种操作: A:从队头那一个到 ...

  2. spark集群进入 bin 下面目录./spark-shell 出现Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

    spark集群启动的时候可以正常,进入 ./spark-shell 就会出现如下错误 配置文件:spark-env.sh export JAVA_HOME=/usr/java/jdk1.7.0_51e ...

  3. 好消息:Dubbo & Spring Boot要来了

    Duboo和Spring Boot都是非常优秀的框架,现在它们要结合了.为了简化Dubbo开发集成,阿里Dubbo团队将发布基于Spring Boot的版本,可快速上手Dubbo的分布式开发,并提供了 ...

  4. 《转》python 9 字典,numpy

    http://www.cnblogs.com/BeginMan/p/3156960.html 一.映射类型 我理解中的映射类型是:键值对的关系,键(key)映射值(value),且它们是一对多的关系. ...

  5. asprise-ocr-api-sample 高价收破解版64 32位

    asprise-ocr-api-sample验证码 高价收破解版64 32位 Reflector 8.5 打开自己的C#代码  完全100%的反编译了

  6. PHP算法之两数相加

    给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和 ...

  7. vue 挂载点 实例 模板

    挂载点:vue实例 里面的el属性 对应的 id 所在的dom节点 模板:指的是挂载点内部的内容           模板可以写在挂载点内部           也可以写在属性里面 demo < ...

  8. ac与ap同步分析

    1 ApStatusRequest : ap把自己的状态发过来做请求  就相当于自我介绍 网关上抓包 : tcpdump -ni br-lan tcp port 8090   -Avv / -w po ...

  9. Altera的primary register和secondary register

    在Altera的一些IP文档上,提到IP的资源使用情况时,会有primary logic register和secondary logic register这样的术语. 那么什么是primary/se ...

  10. thinkphp 自动加载

    在3.2中,基本上无需手动加载类库文件,你可以很方便的完成自动加载. 命名空间自动加载 系统可以通过类的命名空间自动定位到类库文件,例如: 我们定义了一个类 Org\Util\Auth 类: name ...