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 ...
随机推荐
- Cocos Creator—最佳构建部署实践
这篇文章主要是我们团队在使用Cocos Creator过程中的一些关于部署方面的实践总结,标题党了一回,严格来说,应该是<快看漫画游戏研发团队使用Cocos Creator构建部署最佳实践> ...
- gulp源码解析(一)—— Stream详解
作为前端,我们常常会和 Stream 有着频繁的接触.比如使用 gulp 对项目进行构建的时候,我们会使用 gulp.src 接口将匹配到的文件转为 stream(流)的形式,再通过 .pipe() ...
- ASP.NET Core Web API 集成测试中使用 Bearer Token
在 ASP.NET Core Web API 集成测试一文中, 我介绍了ASP.NET Core Web API的集成测试. 在那里我使用了测试专用的Startup类, 里面的配置和开发时有一些区别, ...
- Docker & ASP.NET Core (1):把代码连接到容器
和这种蛋糕一样,Docker的容器和镜像也是使用类似的分层文件系统构建而成的. 这样做的好处就是可以节省硬盘空间,也利于复用等等.因为Docker基于镜像创建容器的时候,其镜像是共享的:而且镜像里面的 ...
- 字典fromkeys方法和update方法
#Author : Kelvin #Date : 2019/1/17 15:27 #字典的update方法,是向调用者字典中添加另外一个字典 dict1 = {"name":&qu ...
- linux日常服务器部署一些命令使用
今天公司的开发环境的linux服务器,我要了一个账号来玩玩 拿到账号和密码,我就用xshell登陆上去 1.查看已挂载的分区列表 df -h 显示已经挂载的分区列表 2.查看目录中的文件 ls 查看目 ...
- 阿里云Ubuntu下安装、配置权限和导入本地mongodb
---恢复内容开始--- 第一部分:首先先在Ubuntu下安装好mongodb,步骤如下: 首先我们需要借助远程管理工具链接到阿里云上的ubuntu系统,接着进行如下操作 一.导出软件源的公钥 sud ...
- HandlerInterceptor拦截实现对PathVariable变量的读取
Http请求拦截作用 拦截后可以修改请求体 拦截后可以作一些其它统一的操作 问题提出 对于很多时间需要拦截很多Http请求,然后去获取一些参数,这些参数可能是querystring串,也可能是路由上的 ...
- 让你的ASP.NET Core应用程序更安全
让你的ASP.NET Core应用程序更安全 对于ASP.NET Core应用程序,除了提供认证和授权机制来保证服务的安全性,还需要考虑下面的一些安全因素: CSRF 强制HTTPS 安全的HTTP ...
- RabbitMQ在Windows环境下的安装与使用
Windows下安装RabbitMQ 环境配置 部署环境 部署环境:windows server 2008 r2 enterprise 官方安装部署文档:http://www.rabbitmq.com ...