598A - Tricky Sum    20171103
$$ans=\frac{n(n+1)}{2} - 2\sum_{k=0}^{\left \lfloor \log_2 n \right \rfloor}{2^{k}}$$

  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. long long t,n,ans;
  9. void init()
  10. {
  11. scanf("%I64d",&n);ans=n*(n+)/;
  12. for(long long i=;i<;i++)if((1ll<<i)<=n)ans-=*(1ll<<i);
  13. printf("%I64d\n",ans);
  14. }
  15. int main()
  16. {
  17. scanf("%I64d",&t);
  18. for(int i=;i<t;i++)init();
  19. return ;
  20. }

598B - Queries on a String    20171103
设t[i]为最终来到位置i的字符的原位置,对每个位置i,倒序遍历每次操作,若有操作区间覆盖到t[i],则可以找出在这次操作之后来到位置t[i]的字符原来在哪个位置,并更新t[i]

  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 m,l[],r[],k[],t[];
  9. string s;
  10. int main()
  11. {
  12. cin>>s;
  13. scanf("%d",&m);
  14. for(int i=;i<=m;i++)
  15. scanf("%d%d%d",&l[i],&r[i],&k[i]),l[i]--,r[i]--;
  16. for(int i=;i<s.size();i++)
  17. {
  18. t[i]=i;
  19. for(int j=m;j>=;j--)
  20. if(l[j]<=t[i] && t[i]<=r[j] && l[j]<r[j])
  21. t[i]=(t[i]-l[j]+r[j]-l[j]+-k[j]%(r[j]-l[j]+))%(r[j]-l[j]+)+l[j];
  22. }
  23. for(int i=;i<s.size();i++)printf("%c",s[t[i]]);
  24. return ;
  25. }

598C - Nearest vectors    20171103

对每个坐标对应的辐角进行排序,显然最小的夹角是来自相邻的两项,O(n)扫一遍即可

  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. #define pi acos(-1.0)
  9. struct rua
  10. {
  11. long double angle;
  12. int id;
  13. }a[];
  14. int n,ans1,ans2;long double x,y,m,_;
  15. bool cmp(rua A,rua B){return A.angle<B.angle;}
  16. int main()
  17. {
  18. scanf("%d",&n);
  19. m=;
  20. for(int i=;i<n;i++)
  21. {
  22. cin>>x>>y;
  23. a[i].angle=atan2(y,x);
  24. a[i].id=i;
  25. }
  26. sort(a,a+n,cmp);
  27. for(int i=;i<n;i++)
  28. {
  29. _=a[(i+)%n].angle-a[i].angle;
  30. if(_<)_+=*pi;
  31. if(_<m)m=_,ans1=a[i].id+,ans2=a[(i+)%n].id+;
  32. }
  33. printf("%d %d\n",ans1,ans2);
  34. return ;
  35. }

598D - Igor In the Museum    20171103

简单并查集,预处理每个区域能看到的壁画数量即可

  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. struct rua
  9. {
  10. int x,y;
  11. }fa[][];
  12. int n,m,k,x,y,ans[][];
  13. char s[][];
  14. char read()
  15. {
  16. char ch=getchar();
  17. while(ch!='.' && ch!='*')
  18. ch=getchar();
  19. return ch;
  20. }
  21. rua Find(int x,int y)
  22. {
  23. if(fa[x][y].x==x && fa[x][y].y==y)return fa[x][y];
  24. else return fa[x][y]=Find(fa[x][y].x,fa[x][y].y);
  25. }
  26. void Union(int xx,int xy,int yx,int yy)
  27. {
  28. fa[Find(xx,xy).x][Find(xx,xy).y]=Find(yx,yy);
  29. }
  30. int calc(int i,int j)
  31. {
  32. int _=;
  33. _+=s[i-][j]=='*';
  34. _+=s[i+][j]=='*';
  35. _+=s[i][j+]=='*';
  36. _+=s[i][j-]=='*';
  37. return _;
  38. }
  39. int main()
  40. {
  41. scanf("%d%d%d",&n,&m,&k);
  42. for(int i=;i<=n;i++)
  43. for(int j=;j<=m;j++)
  44. s[i][j]=read();
  45. for(int i=;i<=n;i++)
  46. for(int j=;j<=m;j++)
  47. fa[i][j].x=i,fa[i][j].y=j;
  48. for(int i=;i<=n;i++)
  49. for(int j=;j<=m;j++)
  50. {
  51. if(s[i][j]=='*')continue;
  52. if(s[i-][j]=='.')Union(i,j,i-,j);
  53. if(s[i][j-]=='.')Union(i,j,i,j-);
  54. }
  55. for(int i=;i<=n;i++)
  56. for(int j=;j<=m;j++)
  57. fa[i][j]=Find(i,j);
  58. for(int i=;i<=n;i++)
  59. for(int j=;j<=m;j++)
  60. if(s[i][j]=='.')
  61. ans[fa[i][j].x][fa[i][j].y]+=calc(i,j);
  62. for(int i=;i<=k;i++)
  63. scanf("%d%d",&x,&y),printf("%d\n",ans[Find(x,y).x][Find(x,y).y]);
  64. return ;
  65. }

598E - Chocolate Bar    20171108

设f[n][m][k]为对应答案,考虑横切竖切的所有情况,记忆化搜索就好了

  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 T,n,m,k,f[][][];
  9. int dfs(int n,int m,int k)
  10. {
  11. if(k==n*m || f[n][m][k] || !k)return f[n][m][k];
  12. int ans=;
  13. for(int i=;i<=n-i;i++)
  14. for(int j=;j<=k;j++)
  15. ans=min(ans,dfs(i,m,j)+dfs(n-i,m,k-j)+m*m);
  16. for(int i=;i<=m-i;i++)
  17. for(int j=;j<=k;j++)
  18. ans=min(ans,dfs(n,i,j)+dfs(n,m-i,k-j)+n*n);
  19. return f[n][m][k]=ans;
  20. }
  21. int main()
  22. {
  23. scanf("%d",&T);
  24. for(int i=;i<=T;i++)
  25. {
  26. scanf("%d%d%d",&n,&m,&k);
  27. printf("%d\n",dfs(n,m,k));
  28. }
  29. return ;
  30. }

598F - Cut Length    20180831

学长的模板真是好用,在模板下面加了几行就过了_(:з」∠)_

贴个链接 http://zjhl2.is-programmer.com/posts/210807.html

  1. /*
  2. 学长的模板
  3. */
  4. LINE l;
  5. int n,m;
  6. POLYGON rua;
  7. int main()
  8. {
  9. scanf("%d%d",&n,&m);
  10. rua.read(n);
  11. while(m--)
  12. l.read(),printf("%.6lf\n",(double)rua.cutlength(l));
  13. return ;
  14. }

Educational Codeforces Round 1的更多相关文章

  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. CentOS ISO版本区别

    CentOS6 CentOS7 介绍 区别 bin-DVD.iso bin-DVD.iso 系统标准安装包 bin DVD本身包含了软件,不需要依赖于网络经行安装. bin-DVD2.iso Ever ...

  2. 第一章 java nio三大组件与使用姿势

    本案例来源于<netty权威指南> 一.三大组件 Selector:多路复用器.轮询注册在其上的Channel,当发现某个或者多个Channel处于“就绪状态”后(accept接收连接事件 ...

  3. Docker 集群Swarm创建和Swarm Web管理

    关于Docker Swarm更多的介绍请查看<Docker管理工具-Swarm部署记录> 一.环境配置 1.安装环境 # cat /etc/redhat-release CentOS Li ...

  4. Deep Learning.ai学习笔记_第五门课_序列模型

    目录 第一周 循环序列模型 第二周 自然语言处理与词嵌入 第三周 序列模型和注意力机制 第一周 循环序列模型 在进行语音识别时,给定一个输入音频片段X,并要求输出对应的文字记录Y,这个例子中输入和输出 ...

  5. springboot-admin自定义事件通知

    springboot-admin组建已经提供了很多开箱即用的通知器(例如邮件),但在有些业务场景下我们需要做一些企业内部的通知渠道,这就需要我们来自定义通知器. 实现其实很简单,只需要往spring注 ...

  6. Jenkins安装卸载

    下载安装去Jenkins官网下载Jenkins,Centos的话会下载到.rpm安装文件 安装.rpm文件使用命令rpm -ivh **.rpm 安装完成之后使用命令rpm -qc jenkins查看 ...

  7. CentOS 6.5 x64下网络配置

    一.自动获取IP地址 #dhclient 自动获取ip地址命令 #ifconfig 查询系统里网卡信息,ip地址.MAC地址 [root@CentOS6 ~]# vi /etc/sysconfig/n ...

  8. [转]Linux Shell 1>/dev/null 2>&1 含义

    shell中可能经常能看到:echo log > /dev/null 2>&1 命令的结果可以通过%>的形式来定义输出 /dev/null :代表空设备文件>  :代表 ...

  9. spring 整合junit进行测试

    如果想让junit和spring容器环境无缝对接的话,可以使用如下方式: import com.jd.ptest.service.ICronService; import org.junit.Test ...

  10. golang中值类型/指针类型的变量区别总结

    转自:https://segmentfault.com/a/1190000012329213 值类型的变量和指针类型的变量 先声明一个结构体: type T struct { Name string ...