Codeforces Good Bye 2018
咕bye 2018,因为我这场又咕咕咕了
无谓地感慨一句:时间过得真快啊(有毒
A.New Year and the Christmas Ornament
分类讨论后等差数列求和
又在凑字数了
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,c;
int main()
{
scanf("%d%d%d",&a,&b,&c);
printf("%d",min(min((a+)*,b*),(c-)*));
return ;
}
B.New Year and the Treasure Geolocation
坐标分别加起来除个$n$,没了
凑字数++
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,a,b,t1,t2;
int main()
{
scanf("%lld",&n);
for(int i=;i<=n;i++) scanf("%lld%lld",&t1,&t2),a+=t1,b+=t2;
for(int i=;i<=n;i++) scanf("%lld%lld",&t1,&t2),a+=t1,b+=t2;
printf("%lld %lld",a/n,b/n);
return ;
}
C.New Year and the Sphere Transmission
分解因数后变成了等差数列求和
凑字数停不下来了?
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n,cnt,facs[N];
long long ans[N];
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int main()
{
scanf("%d",&n);
for(int i=;i*i<=n;i++)
if(n%i==)
{
facs[++cnt]=i;
if(i*i!=n)
facs[++cnt]=n/i;
}
for(int i=;i<=cnt;i++)
{
int g=gcd(facs[i],n),tot=n/g;
ans[i]=1ll*(n-g+)*tot/;
}
sort(ans+,ans++cnt);
for(int i=;i<=cnt;i++)
printf("%lld ",ans[i]);
return ;
}
D.New Year and the Permutation Concatenation
不错的题 终于不在凑字数了
考虑容斥,计算不合法的方案数,这里我们要讲一讲如何实现next_permutation,是这样的:
以 1 3 5 4 2 为例
1.从序列末尾向前扫,直到一个位置pos序列开始下降 1 3 5 4 2
2.从后面这段递减的序列里找到第一个大于*pos的数,将pos位置的数与它交换 1 4 5 3 2
3.排序— —即翻转后面这段原来递减的序列 1 4 2 3 5
这样我们发现后面原来长度为n-pos的这段递减的序列被破坏了,而它原来是可以跟后面的一个排列配对的
那么显然对每个长度$len$统计有长度为$len$的递减序列的排列去掉即可(除了一种情况— —len==n,这时候没有排列能和它配对)
这样一来对每个$len$前$n-len$个可以随便排,后面$len$个又有$C_n^{len}$种选法,所以总方案数就是$\sum\limits_{len=1}^{n-1}\frac{n!}{len!}$,然后从总数里把这个容斥掉即可
#include<cstdio>
const int N=,mod=;
int n,x,y,ans,fac[N],inv[N];
void exGCD(int &x,int &y,int a,int b)
{
if(!b) x=,y=;
else exGCD(y,x,b,a%b),y-=a/b*x;
}
int Inv(int nm,int md)
{
exGCD(x,y,nm,md);
return (x%md+md)%md;
}
int main()
{
scanf("%d",&n),fac[]=inv[]=;
for(int i=;i<=n;i++) fac[i]=1ll*fac[i-]*i%mod;
inv[n]=Inv(fac[n],mod),ans=1ll*n*fac[n]%mod;
for(int i=n-;i;i--) inv[i]=1ll*inv[i+]*(i+)%mod;
for(int i=;i<=n-;i++) ans-=1ll*fac[n]*inv[i]%mod,ans=(ans+mod)%mod;
printf("%d",ans);
return ;
}
E.New Year and the Acquaintance Estimation
观察样例/仔细分析/动手推理可以发现答案是一段隔2连续的区间!(我是第一种
所以只要求上下界就好了,怎么求呢?二分
怎么想到二分的呢?没想到,但是题目贴心地给了一个wiki的链接,里面有这样一个东西

这个定理可以在图的度数降序排好序的情况下检查图是否可行,这明摆着是告诉我们二分啊=。=

我们发现这个式子别的都好说,就是这个
$\sum\limits_{i=k+1}^{n}min(d_i,k)$
很麻烦啊,好像需要什么主席树/multiset?
并不需要,边扫边维护还未出现过的度数小于当前的$k$的点数的和sum即可,说白了就是前缀和,然后每次用$n-i-sum$更新。为什么?因为这就是后面那个式子里$k$的的贡献的增加量(未出现过的大于等于$k$的数)
注意二分+检查之后偏移的方向
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int mem[N],tmp[N],bkt[N];
int n,l,r,rd,ld,hd,sum,odd;
bool cmp(int a,int b)
{
return a>b;
}
int check(int x)
{
int p=,pos=;
memset(bkt,,sizeof bkt);
for(int i=;i<=n;i++)
{
if(mem[i]<x&&p<i)
pos=++p,tmp[pos]=x;
tmp[++p]=mem[i];
}
if(!pos) pos=++p,tmp[pos]=x;
for(int i=;i<=p;i++) bkt[tmp[i]]++;
long long lsum=,rsum=,fsum=;
for(int i=;i<=p;i++)
{
lsum+=tmp[i],bkt[tmp[i]]--;
rsum+=*(i-),rsum-=min(tmp[i],i-);
fsum+=bkt[i-],rsum+=n-i+-fsum;
if(lsum>rsum) return i>=pos?:-;
}
return ;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&mem[i]),sum+=mem[i];
odd=sum%,sort(mem+,mem++n,cmp);
l=,r=(n-odd)/,ld=rd=-;
while(l<=r)
{
int mid=(l+r)/;
if(check(*mid+odd)<) l=mid+;
else ld=mid,r=mid-;
}
l=ld,r=(n-odd)/;
while(l<=r)
{
int mid=(l+r)/;
if(check(*mid+odd)>) r=mid-;
else rd=mid,l=mid+;
}
if(ld==-||rd==-) printf("-1");
else for(int i=ld;i<=rd;i++) printf("%d ",*i+odd);
return ;
}
F.New Year and the Mallard Expedition
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
char mapp[N]; long long len[N];
long long n,wat,spa,ans,sta;
int main()
{
scanf("%lld",&n);
for(int i=;i<=n;i++)
scanf("%lld",&len[i]);
scanf("%s",mapp+);
for(int i=;i<=n;i++)
{
if(mapp[i]=='G')
{
ans+=len[i]*;
spa+=len[i]*;
sta+=len[i];
}
else if(mapp[i]=='W')
{
wat=true;
ans+=len[i]*;
sta+=len[i];
}
else if(mapp[i]=='L')
{
if(sta<len[i])
{
ans+=(wat?:)*(len[i]-sta);
sta=len[i];
}
ans+=len[i];
sta-=len[i];
}
spa=min(spa,sta);
}
if(sta) ans-=sta+spa;//ans-=(5-1)*spa/2,ans-=(3-1)*(sta-spa)/2;
printf("%lld",ans);
return ;
}
首先模拟,草地先走路,水里游泳,岩浆飞过去。在这个过程中我们记录一下是否遇到了水,因为如果遇到岩浆飞不过去的情况,需要在之间走来走去/游来游去积攒体力。模拟的同时记录一个“可以用飞行代替行走”的路程的消耗,这个东西步步和你的耐力取min,最后如果它小于耐力就把它代表的行走换成飞行,如果还剩下一些就把一些游泳也换成飞行
Codeforces Good Bye 2018的更多相关文章
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
- Codeforces Good Bye 2018 D (1091D) New Year and the Permutation Concatenation
题意:给n!个n的排列,按字典序从小到大连成一条序列,例如3的情况为:[1,2,3, 1,3,2, 2,1,3 ,2,3,1 ,3,1,2 ,3,2,1],问其中长度为n,且和为sum=n*(n+1) ...
- Good Bye 2018 (A~F, H)
目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...
- Good Bye 2018
Good Bye 2018 2018年最后一场CF,OVER! 弱弱的我只能做出3道A,B,D~~~~ 最后几分钟,感觉找到了C题的规律,结束的那一刻,提交了一发 "Wrong answer ...
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- Good Bye 2018题解
Good Bye 2018题解 题解 CF1091A [New Year and the Christmas Ornament] 打完cf都忘记写题解了qwq 题意就是:给你一些黄,蓝,红的球,满足蓝 ...
- Codeforces 1091 Good Bye 2018
占个坑先,希望不要掉的太惨了吧,不要掉到上一次之前的rating upt:flag竟然没到,开心. A - New Year and the Christmas Ornament 好像没什么可说的. ...
- codeforces Good Bye 2015 B. New Year and Old Property
题目链接:http://codeforces.com/problemset/problem/611/B 题目意思:就是在 [a, b] 这个范围内(1 ≤ a ≤ b ≤ 10^18)统计出符合二进制 ...
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...
随机推荐
- ELK环境搭建
ELK环境搭建 1. Virtualbox/Vagrant安装 41.1. Virtualbox安装 41.2. Vagrant安装 41.2.1. 简述 41.2.2. Vagrant box 41 ...
- LeetCode-63.不同路径Ⅱ
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为“Finish”). 现在考虑网 ...
- Tomcat部署与使用
Tomcat简介 Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache.Sun和其他一些公司及个人共同开发 ...
- java浮点数存储
转自: [解惑]剖析float型的内存存储和精度丢失问题 1.小数的二进制表示问题 首先我们要搞清楚下面两个问题: (1) 十进制整数如何转化为二进制数 算法很简单.举个例子,11表示成二进制数: ...
- fetch err : "Body not allowed for GET or HEAD requests"
在使用 fetch 的时候 报了 "Body not allowed for GET or HEAD requests" 这个错. 代码如下: 一番google , 找到答案了. ...
- mysql更新表数据时报错 You can't specify target table 'RES_CATALOG_CLASSIFY' for update in FROM clause
You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 将sql语句 UPDATE RES ...
- Daily Scrum 11.10
今日完成任务: 1.加入更改头像功能 2.解决不发送激活邮件和重置密码邮件的问题 3.在服务器上部署网站 4.加入匿名提问功能 明日任务: 黎柱金 修改数据库用户表,实现用户积分管理功能 晏旭瑞 解决 ...
- Scrum Meeting 11.09
成员 今日任务 明日计划 用时 徐越 解决bug:可以重复点赞:answer被选为best answer后点赞数归零:首页不能正确显示问题的回复数.修改搜索功能的代码 继续测试相关app功能,如果达 ...
- 作业1-MathExam
MathExam 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 10 30 • Estim ...
- 2018-2019-20172321 《Java软件结构与数据结构》第六周学习总结
2018-2019-20172321 <Java软件结构与数据结构>第六周学习总结 教材学习内容总结 第10章 树 10.1概述 树由一个包含结点和边的集构成,其中的元素被储存在这些结点中 ...