620A - Professor GukiZ's Robot    20171122

\(ans=max(\left | x2-x1 \right |,\left | y2-y1 \right |)\)

  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<cstring>
  5. #include<iostream>
  6. #include<algorithm>
  7. using namespace std;
  8. int X[],Y[],x,y;
  9. int main()
  10. {
  11. scanf("%d%d%d%d",&X[],&Y[],&X[],&Y[]);
  12. x=abs(X[]-X[]),y=abs(Y[]-Y[]);
  13. printf("%d\n",max(x,y));
  14. return ;
  15. }

620B - Grandfather Dovlet’s calculator    20171122

预处理每个字符的花费,按照题意模拟即可

  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<cstring>
  5. #include<iostream>
  6. #include<algorithm>
  7. using namespace std;
  8. int ans,a,b,f[];
  9. int cal(int k)
  10. {
  11. int _=;
  12. while(k)
  13. _+=f[k%],k/=;
  14. return _;
  15. }
  16. int main()
  17. {
  18. scanf("%d%d",&a,&b);
  19. f[]=,f[]=,f[]=,f[]=,f[]=;
  20. f[]=,f[]=,f[]=,f[]=,f[]=;
  21. for(int i=a;i<=b;i++)
  22. ans+=cal(i);
  23. printf("%d\n",ans);
  24. return ;
  25. }

620C - Pearls in a Row    20171122

开个set记录当前已在区间类的珍珠种类,O(n)扫一遍即可

  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<set>
  5. #include<vector>
  6. #include<cstring>
  7. #include<iostream>
  8. #include<algorithm>
  9. using namespace std;
  10. vector<int>l,r;
  11. int n,x,t=;
  12. set<int>s;
  13. int main()
  14. {
  15. scanf("%d",&n);
  16. for(int i=;i<=n;i++)
  17. {
  18. if(t==i)s.clear();
  19. scanf("%d",&x);
  20. if(s.count(x))
  21. l.push_back(t),r.push_back(i),t=i+;
  22. else s.insert(x);
  23. }
  24. if(!l.size())return printf("-1\n"),;
  25. r[r.size()-]=n;
  26. printf("%d\n",l.size());
  27. for(int i=;i<l.size();i++)
  28. printf("%d %d\n",l[i],r[i]);
  29. return ;
  30. }

620D - Professor GukiZ and Two Arrays    20171122

暴力分类讨论\(k=0,1,2\)的所有情况就好了

  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #define N 2001
  5. #include<cstring>
  6. #include<iostream>
  7. #include<algorithm>
  8. using namespace std;
  9. #define LL long long
  10. struct rua
  11. {
  12. LL i,j,v;
  13. }f[N*N];
  14. LL n,m,d,sa,sb,a[N],b[N],ans[],v[N*N],_,a1,b1,b2;
  15. bool cmp(rua x,rua y){return x.v<y.v;}
  16. void cdx(LL i,LL _)
  17. {
  18. if(!_)return;
  19. if(f[_].i==f[i].i || f[_].j==f[i].j)return;
  20. if(ans[]>abs(d+v[_]))
  21. ans[]=abs(d+v[_]),b1=i,b2=_;
  22. }
  23. int main()
  24. {
  25. ans[]=(1ll<<);
  26. scanf("%I64d",&n);
  27. for(LL i=;i<=n;i++)
  28. scanf("%I64d",&a[i]),sa+=a[i];
  29. scanf("%I64d",&m);
  30. for(LL i=;i<=m;i++)
  31. scanf("%I64d",&b[i]),sb+=b[i];
  32. d=sa-sb;
  33. for(LL i=;i<=n;i++)
  34. for(LL j=;j<=m;j++)
  35. {
  36. f[i*m-m+j].v=*(b[j]-a[i]);
  37. f[i*m-m+j].i=i;
  38. f[i*m-m+j].j=j;
  39. }
  40. ans[]=abs(d);
  41. sort(f+,f+n*m+,cmp);
  42. for(LL i=;i<=n;i++)
  43. for(LL j=;j<=m;j++)
  44. v[i*m-m+j]=f[i*m-m+j].v;
  45. _=lower_bound(v+,v+n*m+,-d)-v;
  46. if(_==n*m+)ans[]=abs(d+v[_-]),a1=_-;else
  47. if(_==)ans[]=abs(d+v[]),a1=_;else
  48. if(abs(d+v[_])<abs(d+v[_-]))ans[]=abs(d+v[_]),a1=_;
  49. else ans[]=abs(d+v[_-]),a1=_-;
  50. for(int i=;i<n*m;i++)
  51. {
  52. d+=v[i];
  53. _=lower_bound(v+,v+n*m+,-d)-v;
  54. if(_==n*m+)cdx(i,_-);
  55. else if(_==)cdx(i,-(i==));else
  56. cdx(i,_+(i==_)),cdx(i,_--(i==_-));
  57. d-=v[i];
  58. }
  59. if(ans[]<=ans[] && ans[]<=ans[])
  60. return printf("%I64d\n0\n",ans[]),;
  61. if(ans[]<=ans[] && ans[]<=ans[])
  62. return printf("%I64d\n1\n%I64d %I64d\n",ans[],f[a1].i,f[a1].j),;
  63. printf("%I64d\n2\n",ans[]);
  64. printf("%I64d %I64d\n",f[b1].i,f[b1].j);
  65. printf("%I64d %I64d\n",f[b2].i,f[b2].j);
  66. return ;
  67. }

620E - New Year Tree    20180919

预处理每个点的DFS序,可以得出每棵子树对应的DFS序的范围。由于\(c_i\)不超过60,故可将修改操作转换为:把子树内所有点的价值改为\(2^{c}\),将询问操作转换为:询问子树内所有点价值进行或运算的结果在二进制中1的个数,用线段树做就好了

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define N 400001
  4. #define LL long long
  5. vector<int>d[N];
  6. int n,m,t,x,y,c[N],l[N],r[N];
  7. struct rua{int l,r;LL f,w;}tr[N<<];
  8. LL a[N];
  9. void update(int x)
  10. {
  11. int lson=x*,rson=x*+;
  12. tr[x].w=tr[lson].w|tr[rson].w;
  13. }
  14. void down(int x)
  15. {
  16. LL c=tr[x].w;tr[x].f=;
  17. int lson=x*,rson=x*+;
  18. tr[lson].f=tr[lson].w=c;
  19. tr[rson].f=tr[rson].w=c;
  20. }
  21. void Build(int l,int r,int x)
  22. {
  23. tr[x]={l,r,,};
  24. if(l==r){tr[x].w=a[l];return;}
  25. int mid=l+r>>;
  26. Build(l,mid,x*);
  27. Build(mid+,r,x*+);
  28. update(x);
  29. }
  30. void Change(int L,int R,LL c,int x)
  31. {
  32. int l=tr[x].l,r=tr[x].r;
  33. int mid=l+r>>;
  34. if(L<=l && r<=R){tr[x].f=tr[x].w=c;return;}
  35. if(tr[x].f)down(x);
  36. if(L<=mid)Change(L,R,c,x*);
  37. if(R>mid)Change(L,R,c,x*+);
  38. update(x);
  39. }
  40. LL Query(int L,int R,int x)
  41. {
  42. int l=tr[x].l,r=tr[x].r;
  43. int mid=l+r>>;
  44. LL res=;
  45. if(L<=l && r<=R)return tr[x].w;
  46. if(tr[x].f)down(x);
  47. if(L<=mid)res|=Query(L,R,x*);
  48. if(R>mid)res|=Query(L,R,x*+);
  49. update(x);
  50. return res;
  51. }
  52. void dfs(int cur,int pre)
  53. {
  54. l[cur]=++x;
  55. a[x]=1ll<<c[cur];
  56. for(auto nxt:d[cur])if(nxt!=pre)dfs(nxt,cur);
  57. r[cur]=x;
  58. }
  59. int main()
  60. {
  61. scanf("%d%d",&n,&m);
  62. for(int i=;i<=n;i++)
  63. scanf("%d",&c[i]);
  64. for(int i=;i<=n;i++)
  65. scanf("%d%d",&x,&y),
  66. d[x].push_back(y),
  67. d[y].push_back(x);
  68. x=,dfs(,);
  69. Build(,n,);
  70. for(int i=;i<=m;i++)
  71. {
  72. scanf("%d",&t);
  73. if(t==)
  74. scanf("%d%d",&x,&y),
  75. Change(l[x],r[x],1ll<<y,);
  76. else
  77. scanf("%d",&x),
  78. printf("%d\n",(int)__builtin_popcountll(Query(l[x],r[x],)));
  79. }
  80. }

620F - Xors on Segments    20171122

这题...预处理从1异或到n的值(即前缀异或和),\(O(n^{2})\)莽一下就过了...CF的评测机是跑得真快

  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #define N 50001
  5. #define M 1000001
  6. #include<cstring>
  7. #include<iostream>
  8. #include<algorithm>
  9. using namespace std;
  10. int n,m,a[N],l[N],r[N],t[N],ans[N],f[M];
  11. int main()
  12. {
  13. for(int i=;i<M;i++)
  14. f[i]=f[i-]^i;
  15. scanf("%d%d",&n,&m);
  16. for(int i=;i<=n;i++)
  17. scanf("%d",&a[i]);
  18. for(int i=;i<=m;i++)
  19. scanf("%d%d",&l[i],&r[i]);
  20. for(int i=;i<=n;i++)
  21. {
  22. int _=;t[i-]=;
  23. for(int j=i;j<=n;j++)
  24. _=max(_,f[a[i]]^f[a[j]]^min(a[i],a[j])),t[j]=_;
  25. for(int j=;j<=m;j++)
  26. if(l[j]<=i && r[j]>=i)
  27. ans[j]=max(ans[j],t[r[j]]);
  28. }
  29. for(int i=;i<=m;i++)printf("%d\n",ans[i]);return ;
  30. }

Educational Codeforces Round 6的更多相关文章

  1. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  2. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  3. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  4. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  5. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  6. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  7. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

随机推荐

  1. MySQL学习笔记(五)并发时经典常见的死锁原因及解决方法

    MySQL都有什么锁? MySQL有三种锁的级别:页级.表级.行级. 表级锁:开销小,加锁快:不会出现死锁:锁定粒度大,发生锁冲突的概率最高,并发度最低. 行级锁:开销大,加锁慢:会出现死锁:锁定粒度 ...

  2. 使用SIGALARM为recvfrom设置超时

    static void sig_alrm(int); void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) ...

  3. SSRF漏洞挖掘经验

    SSRF概述 SSRF(Server-Side Request Forgery:服务器端请求伪造) 是一种由攻击者构造形成由服务端发起请求的一个安全漏洞.一般情况下,SSRF攻击的目标是从外网无法访问 ...

  4. Ubuntu解决没有可安装候选软件包

    解决方法:可以使用apt-cache search <package_name>寻找. 例如: E: 软件包 libqglviewer-dev 没有可安装候选 解决方法: apt-cach ...

  5. LOJ #2116 Luogu P3241「HNOI2015」开店

    好久没写数据结构了 来补一发 果然写的时候思路极其混乱.... LOJ #2116 Luogu P3241 题意 $ Q$次询问,求树上点的颜色在$ [L,R]$中的所有点到询问点的距离 强制在线 询 ...

  6. jsonp跨域ajax跨域get方法

    原理: 就是利用<script >标签没有跨域限制的,从而达到与第三方网站通讯的目的.当需要通讯时,本站脚本创建一个<script>标签,src地址指向第三方网站的的一个网址. ...

  7. Centos6.X搭建Squid为YUM做代理

    1.在能联网的机器上安装 Squid yum install squid 2.配置squid vi /etc/squid/squid.conf 编辑内容如下: http_port cache_mem ...

  8. 解决tomcat端口被占用:Port 8005 required by Tomcat v7.0 Server at localhost is already in use

    问题提示8005端口被占用 首先:在cmd下,输入  netstat   -ano|findstr  8005 (什么端口号被占用就输入什么端口号),回车 再输入 taskkill  /pid  20 ...

  9. c4b和c4f的区别

    1. cc.c4b的参数直接填rgba的值. 2 .cc.c4f(r,g,b,透明度),把rgb值填进去,会发现颜色不对,需要把rgb值除以255,所以最终转换公式是: cc.c3b(r,g,b) = ...

  10. (转)http authorization 基本认证

    转:https://www.cnblogs.com/chenrong/articles/5818498.html http协议是无状态的, 浏览器和web服务器之间可以通过cookie来身份识别. 桌 ...