Codeforces Goodbye 2018
Goodbye 2018
- 可能是我太菜考试的时候出不了$E$
- 可能是我太菜考试的时候调不出$F$
- 所以转化为手速场之后手速还上不去.jpg
A
模拟题意...
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int y,b,r,ans=1<<30;
scanf("%d%d%d",&y,&b,&r);
ans=min(r-2,min(b-1,y));
printf("%d\n",ans*3+3);
}
B
因为一定有,所以就一定是一个位置。
然后就相当于是给你$2\times n$个点,两两匹配的中点在同一个点的方案。
然后就直接横坐标纵坐标求平均数即可.jpg
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define ll long long
int n,x,y;ll a,b;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n<<1;i++)
{
scanf("%d%d",&x,&y);
a+=x,b+=y;
}
printf("%lld %lld\n",a/n,b/n);
}
C
推一下式子就完事了.jpg
可以发现,跳的步数一定是$n$的约数,然后发现构成的节点是等差数列。
然后发现,直接暴力求即可...
最后需要排个序...
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define ll long long
ll n,ans[1000005];
int tot;
int main()
{
scanf("%lld",&n);
for(ll i=1;i*i<=n;i++)
{
if(n%i==0)
{
ans[++tot]=(2+n-i)*(n/i)>>1;
ans[++tot]=(2+n-(n/i))*i>>1;
}
}
sort(ans+1,ans+tot+1);
tot=unique(ans+1,ans+tot+1)-ans-1;
for(int i=1;i<=tot;i++)printf("%lld ",ans[i]);puts("");
}
D
比较好玩的数数题.jpg
(可能我的数数题也就是这么菜鸡吧.jpg
OEIS了一发,并没有.jpg
然后我们考虑,答案一定会长成这个样子:$n\times n!-\sum\limits_{i=1}^{n-1}\frac{n!}{i!}$
表达的含义很简单,就是对于两个字典序相近的排列,假设前一个字典序结尾有$K$位是递减的,那么说明,下次变动的时候,会有$K+1$为被改掉了,其他的位没有动。
然后可以发现,其他的$n-K$位都能依旧构成一个满足要求的序列,而剩下的$K+1$位都不能满足...
对于这样的前缀,一共有$\frac{n!}{k!}$个,所以答案就是$n\times n!-\sum\limits_{i=1}^{n-1}\frac{n!}{i!}$
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define N 1000010
#define ll long long
#define mod 998244353
int n;
ll f[N],g[N],ans,inv[N];
inline ll q_pow(ll x,int n){ll ret=1;for(;n;n>>=1,x=x*x%mod)if(n&1)ret=ret*x%mod;return ret;}
int main()
{
scanf("%d",&n);
f[0]=1ll;
for(int i=1;i<=n;i++)
f[i]=(f[i-1]*i)%mod,inv[i]=q_pow(f[i],mod-2);
for(int i=1;i<=n;i++)g[i]=(f[n]*inv[n-i])%mod;
(ans+=f[n])%=mod;
for(int i=2;i<n;i++)(ans+=(g[n-i]*(f[i]-1+mod))%mod)%=mod;
printf("%lld\n",ans);
return 0;
}
证明好难.jpg
E
下次题目中的蓝字一定要点开,然后翻译一下,说不定就有题解...
我们发现,对于答案方案来说,一定是满足连续性的,也就是说$K,K+4$是答案,那么$K+2$也一定是答案.jpg
原因很简单,就是说,可以让前面的某俩人互相匹配上,就不用和最后一个人匹配了...
并且可以发现,对于这样的匹配变动,在找到一个最小的满足答案要求的$a_{n+1}$的时候,就不能再找到一个新的变动了
然后就是如何找到答案...
然后那个蓝字中有这样的一个式子.jpg
对于图,满足:对于任意一个$k$满足$\sum\limits_{i=1}^kd_i \le k\times(k-1)+\sum\limits_{i=k+1}n\min(d_i,k)$,并且$\sum\limits_{i=1}nd_i$为偶数...
那么我们就可以维护了.jpg
先二分答案,然后考虑如何验证...
对于一个$d_{n+1}$,如果它在排序后位于$t$这个位置,那么如果最先不满足条件的位置$K< t$,说明这个$d_i$太小了...
如果最先不满足跳脚的位置$K\ge t$,那么说明这个$d_i$太大了。
所以根据这个就可以找到最大值和最小值了...
然后就完事了...
至于怎么$O(n)$验证:插入排序...
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 500005
#define ll long long
int a[N],n,d[N],pos[N];ll s[N];
int check(int x)
{
int flg=0;d[n+1]=-1;
for(int i=1,j=0;i<=n;i++)
{
if(flg||a[i]>=x)d[++j]=a[i];
else flg=++j,d[j]=x,i--;
}
if(!flg)d[n+1]=x,flg=n+1;
s[0]=0;
for(int i=1;i<=n+1;i++)s[i]=d[i]+s[i-1];//,printf("%d ",d[i]);;puts("");
for(int i=n+1,now=1;i;i--)
while(now<=n+1&&d[i]>now)pos[now++]=i;
for(int k=1;k<=n+1;k++)
{
ll tmp=s[k]-(ll)k*(k-1);
tmp-=(ll)k*max(pos[k]-k,0);tmp-=s[n+1]-s[pos[k]];
// printf("%d %d %d %lld\n",x,k,pos[k],tmp);
if(tmp>0)return k<flg?-1:1;
}return 0;
}
int main()
{
scanf("%d",&n);int flg=0;
for(int i=1;i<=n;i++)scanf("%d",&a[i]),flg^=(a[i]&1);
sort(a+1,a+n+1);reverse(a+1,a+n+1);
int l=0,r=(n>>1)+1;
while(l<r)
{
int m=(l+r)>>1;
if(check((m<<1)|flg)!=-1)r=m;
else l=m+1;
}
if(check((l<<1)|flg))return puts("-1"),0;
int ans=l;r=(n>>1)+1;
while(l<r)
{
int m=(l+r)>>1;
// printf("%d %d %d %d\n",l,m,r,check((m<<1)|flg));
if(!check((m<<1)|flg))l=m+1;
else r=m;
}l--;
ans=(ans<<1)|flg,l=(l<<1)|flg;
for(int i=ans;i<=l;i+=2)printf("%d ",i);
}
F
通过分析性质可以发现,能在水里多游绝不在草上多走...能在草上走,绝不在水里多游...能在草上飞,就不在水里飞...
然后就变成了增加两个位置的长度了...
分别是:第一块和第一块水...
然后就模拟就好了...
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define N 100005
#define ll long long
int n,flg;ll a[N],now,ans,res,tmp;
char s[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);scanf("%s",s+1);
flg=1;
for(int i=1;i<=n;i++)
{
if(s[i]=='W'&&s[flg]=='G')flg=i;
if(s[i]=='L')now-=a[i];
else now+=a[i];
if(now<=0)a[flg]-=now,now=0;
}
now=0;
for(int i=1;i<=n;i++)
{
ll tmp=a[i];
if(s[i]=='W')now+=tmp,ans+=2*tmp;
if(s[i]=='G')
{
ll tnp=min(tmp,now);
now-=tnp,ans+=2*tnp;
ans+=3*(tmp-tnp);
}
if(s[i]=='L')
{
ll tnp=min(tmp,now);
now-=tnp,tmp-=tnp,ans+=2*tnp;
ans+=3*tmp;
}
}
printf("%lld\n",ans);
}
//sdasdasdas
剩下的还不会,回头补题吧QaQ
Codeforces Goodbye 2018的更多相关文章
- goodbye 2018, hello 2019
纵使不愿意,终究还是到了岁末. 2018 即将过去的一年,已经完成的事情自己做得不足.年初计划要做的几件事情都做了,感觉没有尽力去做好. 工作 16年毕业之后到今年,算是真正意义上完成从学生时 ...
- Codeforces Hello 2018 E题Logical Expression dp+最短路 好题
j题目链接: http://codeforces.com/contest/913/problem/E 题意: 给你x,y,z三个变量,与& 或| 非! 括号() 四种运算符,规定括 ...
- Codeforces - Gym102028 - 2018 Jiaozuo Regional Contest
http://codeforces.com/gym/102028 A. Xu Xiake in Henan Province 看起来像水题.乱搞一下,还真是. #include<bits/std ...
- Codeforces Hello 2018 C - Party Lemonade
传送门:http://codeforces.com/contest/913/problem/C 有n类物品,第i(i=0,1,2,...,n-1)类物品的价值为2i,花费为ci.任意选择物品,使得总价 ...
- CodeForces Goodbye 2017
传送门 A - New Year and Counting Cards •题意 有n张牌,正面有字母,反面有数字 其中元音字母$a,e,o,i,u$的另一面必须对应$0,2,4,6,8$的偶数 其他字 ...
- Week Five
2018.12.25 1.[BZOJ 4310] 2.[BZOJ 3879] 3.[BZOJ 2754] 4.[BZOJ 4698] 5.[Codeforces 914E] 6.[Codeforces ...
- CF500G / T148321 走廊巡逻
题目链接 这题是 Codeforces Goodbye 2014 的最后一题 CF500G,只是去掉了 \(u \not= x, v \not = v\) 的条件. 官方题解感觉有很多东西说的迷迷瞪瞪 ...
- Codeforces Avito Code Challenge 2018 D. Bookshelves
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...
- Codeforces 1023 A.Single Wildcard Pattern Matching-匹配字符 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)
Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Patter ...
随机推荐
- 从零开始学习和改造activiti流程引擎的13天,自己记录一下
day#1(11.13) 尝试通过spring boot 集成最新版activiti 7,但是苦于官方的文档基本为空,无法完成spring boot的配置,最终按照activiti 6的文档,手工初始 ...
- JQuery 常用的那些东西
CDN Google CDN Microsoft CDN CDNJS CDN jsDelivr CDN 选择器 jQuery 元素选择器和属性选择器允许您通过标签名.属性名或内容对 HTML 元素进行 ...
- Pytorch实战1:线性回归(Linear Regresion)
GitHub代码练习地址:https://github.com/Neo-ML/MachineLearningPractice/blob/master/Pytorch01_LinearRegressio ...
- 第一周 IP通信基础学习回顾
这周的课程首先让我们学习了计算机网络概述,了解计算机网络的定义和功能分别是:资源共享,信息传输与集中处理,负载均衡与分布处理,综合信息服务.同时也对计算机网络的演进,计算机网络的分类,计算机网络的性能 ...
- springboot v2.0.3版本多数据源配置
本篇分享的是springboot多数据源配置,在从springboot v1.5版本升级到v2.0.3时,发现之前写的多数据源的方式不可用了,捕获错误信息如: 异常:jdbcUrl is requir ...
- Linux知识要点大全(第四章)
第四章 文件管理 *主要内容 文件和目录的操作: ①创建 ②删除 ③拷贝 ④重命名(剪切) ⑤查看 一:目录的操作 回顾与目录相关的命令 ls 查看目录中的内容 .pwd 打印当前目录 .cd ...
- Prometheus安装和配置node_exporter监控主机
Node_exporter是可以在* Nix和Linux系统上运行的计算机度量标准的导出器. Node_exporter 主要用于暴露 metrics 给 Prometheus,其中 metrics ...
- ProgressWheelDialogUtil【ProgressWheel Material样式进度条对话框】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 简单封装网络请求时的加载对话框以及上传.下载文件的进度加载对话框. 效果图 代码分析 ProgressWheel : 自定义view ...
- 使用JDBC连接操作数据库
JDBC简介 Java数据库连接(Java Database Connectivity,JDBC),是一种用于执行SQL语句的Java API,它由一组用Java编程语言编写的类和接口组成. JDBC ...
- 使用EHPC实现“完美并行”的高效批处理方案
使用EHPC实现“完美并行”的高效批处理方案 在高性能计算场景中,用户一次业务计算可以划分为大量的任务,每个任务的处理逻辑相同,但是输入文件.参数设置和输出文件不同.由于每个任务处理逻辑相似,执行时彼 ...