Educational Codeforces Round 1
598A - Tricky Sum 20171103
$$ans=\frac{n(n+1)}{2} - 2\sum_{k=0}^{\left \lfloor \log_2 n \right \rfloor}{2^{k}}$$
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long t,n,ans;
void init()
{
scanf("%I64d",&n);ans=n*(n+)/;
for(long long i=;i<;i++)if((1ll<<i)<=n)ans-=*(1ll<<i);
printf("%I64d\n",ans);
}
int main()
{
scanf("%I64d",&t);
for(int i=;i<t;i++)init();
return ;
}
598B - Queries on a String 20171103
设t[i]为最终来到位置i的字符的原位置,对每个位置i,倒序遍历每次操作,若有操作区间覆盖到t[i],则可以找出在这次操作之后来到位置t[i]的字符原来在哪个位置,并更新t[i]
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int m,l[],r[],k[],t[];
string s;
int main()
{
cin>>s;
scanf("%d",&m);
for(int i=;i<=m;i++)
scanf("%d%d%d",&l[i],&r[i],&k[i]),l[i]--,r[i]--;
for(int i=;i<s.size();i++)
{
t[i]=i;
for(int j=m;j>=;j--)
if(l[j]<=t[i] && t[i]<=r[j] && l[j]<r[j])
t[i]=(t[i]-l[j]+r[j]-l[j]+-k[j]%(r[j]-l[j]+))%(r[j]-l[j]+)+l[j];
}
for(int i=;i<s.size();i++)printf("%c",s[t[i]]);
return ;
}
598C - Nearest vectors 20171103
对每个坐标对应的辐角进行排序,显然最小的夹角是来自相邻的两项,O(n)扫一遍即可
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define pi acos(-1.0)
struct rua
{
long double angle;
int id;
}a[];
int n,ans1,ans2;long double x,y,m,_;
bool cmp(rua A,rua B){return A.angle<B.angle;}
int main()
{
scanf("%d",&n);
m=;
for(int i=;i<n;i++)
{
cin>>x>>y;
a[i].angle=atan2(y,x);
a[i].id=i;
}
sort(a,a+n,cmp);
for(int i=;i<n;i++)
{
_=a[(i+)%n].angle-a[i].angle;
if(_<)_+=*pi;
if(_<m)m=_,ans1=a[i].id+,ans2=a[(i+)%n].id+;
}
printf("%d %d\n",ans1,ans2);
return ;
}
598D - Igor In the Museum 20171103
简单并查集,预处理每个区域能看到的壁画数量即可
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct rua
{
int x,y;
}fa[][];
int n,m,k,x,y,ans[][];
char s[][];
char read()
{
char ch=getchar();
while(ch!='.' && ch!='*')
ch=getchar();
return ch;
}
rua Find(int x,int y)
{
if(fa[x][y].x==x && fa[x][y].y==y)return fa[x][y];
else return fa[x][y]=Find(fa[x][y].x,fa[x][y].y);
}
void Union(int xx,int xy,int yx,int yy)
{
fa[Find(xx,xy).x][Find(xx,xy).y]=Find(yx,yy);
}
int calc(int i,int j)
{
int _=;
_+=s[i-][j]=='*';
_+=s[i+][j]=='*';
_+=s[i][j+]=='*';
_+=s[i][j-]=='*';
return _;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
s[i][j]=read();
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
fa[i][j].x=i,fa[i][j].y=j;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
if(s[i][j]=='*')continue;
if(s[i-][j]=='.')Union(i,j,i-,j);
if(s[i][j-]=='.')Union(i,j,i,j-);
}
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
fa[i][j]=Find(i,j);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(s[i][j]=='.')
ans[fa[i][j].x][fa[i][j].y]+=calc(i,j);
for(int i=;i<=k;i++)
scanf("%d%d",&x,&y),printf("%d\n",ans[Find(x,y).x][Find(x,y).y]);
return ;
}
598E - Chocolate Bar 20171108
设f[n][m][k]为对应答案,考虑横切竖切的所有情况,记忆化搜索就好了
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int T,n,m,k,f[][][];
int dfs(int n,int m,int k)
{
if(k==n*m || f[n][m][k] || !k)return f[n][m][k];
int ans=;
for(int i=;i<=n-i;i++)
for(int j=;j<=k;j++)
ans=min(ans,dfs(i,m,j)+dfs(n-i,m,k-j)+m*m);
for(int i=;i<=m-i;i++)
for(int j=;j<=k;j++)
ans=min(ans,dfs(n,i,j)+dfs(n,m-i,k-j)+n*n);
return f[n][m][k]=ans;
}
int main()
{
scanf("%d",&T);
for(int i=;i<=T;i++)
{
scanf("%d%d%d",&n,&m,&k);
printf("%d\n",dfs(n,m,k));
}
return ;
}
598F - Cut Length 20180831
学长的模板真是好用,在模板下面加了几行就过了_(:з」∠)_
贴个链接 http://zjhl2.is-programmer.com/posts/210807.html
/*
学长的模板
*/
LINE l;
int n,m;
POLYGON rua;
int main()
{
scanf("%d%d",&n,&m);
rua.read(n);
while(m--)
l.read(),printf("%.6lf\n",(double)rua.cutlength(l));
return ;
}
Educational Codeforces Round 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 ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [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 ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- 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 ...
- 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 ...
随机推荐
- bat获取文件夹里面所有文件夹的名称方法
创建一个123.txt文档,修改名称为123.bat 里面填写内容如下: DIR *.* /B >文件名清单.TXT 保存,双击执行即可获取生成文件夹名称的txt文档
- springboot获取properties文件的配置内容(转载)
1.使用@Value注解读取读取properties配置文件时,默认读取的是application.properties. application.properties: demo.name=Name ...
- .NET上传大文件时提示Maximum request length exceeded错误的解决方法
使用IIS托管应用程序时,当我们需要上传大文件(4MB以上)时,应用程序会提示Maximum request length exceeded的错误信息.该错误信息的翻译:超过最大请求长度. 解决方法: ...
- Elasticsearch集群运维
一.索引管理 1. 创建索引 PUT test-2019-03 { "settings": { "index": { "number_of_shard ...
- Eclipse创建第一个Spring Boot项目
一.安装SpringBoot插件 安装过程需要联网下载插件,属于在线安装,请耐心等待安装完成,下载安装完成以后,需要重启Eclipse 二.创建Spring Boot项目 如下图所示new-other ...
- 【网络安全】SSLSplit实现中间人攻击
中间人攻击,即在中间监听获取网络数据以便获取的有价值的信息实现攻击破坏的目的,即client-mid man-server,此处介绍的sslsplit可以作为mid man监听ssl信息及HTTP信息 ...
- protobuf 动态创建
https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/index.html https://originlee.com/2015/03/14/ana ...
- MySQL 8 中新的复制功能
MySQL 8 中新的复制功能使得操作更加方便,并帮助用户更好地观察复制过程中内部发生的情况. 使用 MySQL 5.7.17 获取 MySQL 组复制插件是一项巨大的工作.组复制是一个新的插件,通过 ...
- 【理论面试篇】收集整理来自网络上的一些常见的 经典前端、H5面试题 Web前端开发面试题
##2017.10.30收集 面试技巧 5.1 面试形式 1) 一般而言,小公司做笔试题:大公司面谈项目经验:做地图的一定考算法 2) 面试官喜欢什么样的人 ü 技术好. ...
- 【PHP】解析PHP中的函数
目录结构: contents structure [-] 可变参数的函数 变量函数 回调函数 自定义函数库 闭包(Closure)函数的使用 在这篇文章中,笔者将会讲解如何使用PHP中的函数,PHP是 ...