Educational Codeforces Round 7
622A - Infinite Sequence 20171123
暴力枚举\(n\)在哪个区间即可,时间复杂度为\(O(\sqrt{n})\)
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long n;
int main()
{
scanf("%I64d",&n);
for(long long i=;;i++)
if(i*(i+)/>=n)
return printf("%I64d\n",n-i*(i-)/),;
}
622B - The Time 20171123
没什么好说的......
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int h,m,a;
void print(int k)
{
if(k<)printf("0%d",k);
else printf("%d",k);
}
int main()
{
scanf("%d:%d%d",&h,&m,&a);
m+=a;h+=m/;m%=;h%=;
print(h);printf(":");print(m);
return ;
}
622C - Not Equal on a Segment 20171123
设f[i]为前i个数里不同数的个数,然后瞎几把乱搞就好了_(:з」∠)_
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#define N 1000001
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a[N],l,r,x,_,f[N];
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
f[i]=f[i-]+(a[i]!=a[i-]);
}
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&l,&r,&x);
if(f[l]==f[r] && a[l]==x)
{printf("-1\n");continue;}
if(a[l]!=x)printf("%d\n",l);else
printf("%d\n",upper_bound(f+l,f+r,f[l])-f);
}
return ;
}
622D - Optimal Number Permutation 20171123
构造题...朝着让结果为0的目标去就好了
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a,b,f[];
int main()
{
scanf("%d",&n);a=,b=n+;
for(int i=;i<n;i++)f[a]=f[a+n-i]=i,a++,swap(a,b);f[a]=f[*n]=n;
for(int i=;i<=*n;i++)printf("%d%c",f[i],i==*n?'\n':' ');
return ;
}
622E - Ants in Leaves 20180919
考虑从根节点连出去的几个子树的答案是多少,对于每个子树,把子树中所有的叶子节点按深度排序,若设f[i]为第i个叶子爬到子树的根结点所需要的时间,则f[i]的初始值为他的深度,且有\(f_i=max(f_{i},f_{i-1}+1)\)。最终答案就是所有子树对应答案的最大值
#include<bits/stdc++.h>
using namespace std;
#define N 500001
int n,u,v,ans,cnt,f[N];
vector<int>d[N];
void dfs(int cur,int pre,int dep)
{
int x=;
for(auto nxt:d[cur])if(nxt!=pre)
x=,dfs(nxt,cur,dep+);
if(!x)f[++cnt]=dep;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&u,&v),
d[u].push_back(v),
d[v].push_back(u);
for(auto i:d[])
{
cnt=;
dfs(i,,);
sort(f+,f+cnt+);
for(int i=;i<=cnt;i++)
f[i]=max(f[i],f[i-]+);
ans=max(ans,f[cnt]+);
}
return printf("%d\n",ans),;
}
622F - The Sum of the k-th Powers 20180317
拉格朗日插值法的经典应用
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#define N 1000005
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define MOD 1000000007
LL n,k,t,ans,inv[N],y[N],f[N];
LL qow(LL X,LL Y){return Y?(Y&?X*qow(X,Y-)%MOD:qow(X*X%MOD,Y/)):;}
int main()
{
scanf("%I64d%I64d",&n,&k);
inv[]=f[]=t=;
for(LL i=;i<=k+;i++)
inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
for(LL i=;i<=k+;i++)
f[i]=f[i-]*inv[i]%MOD;
for(LL i=;i<=k+;i++)
y[i]=(y[i-]+qow(i,k))%MOD;
if(n<=k+)return printf("%I64d\n",y[n]),;
for(LL i=;i<=k+;i++)
t*=(n-i)%MOD,t%=MOD;
for(LL i=;i<=k+;i++)
{
LL s=((i-k)%)?-:,res=y[i];
res*=t*qow((n-i)%MOD,MOD-)%MOD,res%=MOD;
res*=f[i-]*f[k+-i]%MOD,res%=MOD;
ans+=(res*s+MOD)%MOD,ans%=MOD;
}
printf("%I64d\n",ans);
return ;
}
Educational Codeforces Round 7的更多相关文章
- [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 ...
随机推荐
- Ubuntu 开机自动挂载硬盘
1.查看Linux硬盘信息: $ sudo fdisk -l 2.格式化硬盘(根据需要确定文件系统): sudo mkfs.xfs /dev/sdb 3.创建/data目录 sudo mkdir /d ...
- mysql MHA架构搭建过程
[环境介绍] 系统环境:Red Hat Enterprise Linux 7 + 5.7.18 + MHA version 0.57 系统 IP 主机名 备注 版本 xx系统 192.168.142. ...
- [物理学与PDEs]第5章习题3 第二 Piola 应力张量的对称性
试证明: 在物质描述下, 动量矩守恒定律等价于第二 Piola 应力张量的对称性. 证明: 由 $$\beex \bea \int_{G_t}\rho\sex{{\bf y}\times\cfrac{ ...
- Python列表中查找某个元素的索引(多个)
enumerate() 函数用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中. 以下是 enumerate() 方法的语法: e ...
- mysql和SQLYog工具使用
在做 android java web开发过程中,需要用到mysql数据库,使用可视化工具SQLYog管理工具,现介绍如下: 首先下载mysql工具 下载地址 https://dev.mysql. ...
- [转] Python 字符编码判断
转自:http://www.cnblogs.com/dkblog/archive/2011/03/02/1980644.html 法一: isinstance(s, str) 用来判断是否为一般字符串 ...
- spring cloud 微服务调用--ribbon和feign调用
这里介绍ribbon和feign调用两种通信服务调用方式,同时介绍如何引入第三方服务调用.案例包括了ribbon负载均衡和hystrix熔断--服务降级的处理,以及feign声明式服务调用.例子包括s ...
- zabbix3.2监控mongodb
模板地址:https://share.zabbix.com/databases/mongodb/mongodb-for-zabbix-3-2 .安装jq依赖 # yum install jq -y . ...
- open live write 代码高亮插件的配置和使用
第一步:下载open live writer插件,下载地址:http://www.cnblogs.com/memento/p/5995173.html 第二步:找到open live writer的安 ...
- Java项目使用SQLite数据库后无法启动的问题
背景: Java > maven 的 jar 项目 功能是记录用户的每天的按键次数 使用 jar2exe 工具将 jar 转为 exe 可执行文件 原本项目中使用的Mysql数据库,使用Myba ...