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 ...
随机推荐
- HTML学习1-Dom之事件绑定
事件: 1.注册事件 a. <div onxxxx=””></div> b. document .onxxxx= function() //找到这个标签 2.this,触发 ...
- word2vec入门理解的博客整理
深度学习word2vec笔记之基础篇 https://blog.csdn.net/mytestmy/article/details/26961315 深度学习word2vec笔记之算法篇 https: ...
- mkswap命令详解
基础命令学习目录首页 原文链接:http://blog.51cto.com/arlen99/1743841 mkswap命令用于在一个文件或者设备上建立交换分区.在建立完之后要使用sawpon命令开始 ...
- lspci命令详解
基础命令学习目录首页 最近经常用到 lspci -nn | grep Eth 命令,需要学习下PCI总线,找到一篇文章,虽然也是转载,但写的较清晰,再次转载下. http://blog.csdn.ne ...
- 【Py大法系列--01】20多行代码生成你的微信聊天机器人
前言 近期Stack Overflow公布了一项调查显示,Python已经成了发展最快的主流编程语言,Python搭乘着数据科学和机器学习以及人工智能的浪潮,席卷了整个技术圈.越来越多的人想了解.想学 ...
- PHP使用Sublime Text3技巧
1 下载安装 2 安装Package Control 3 安装插件 4 快捷键 5 项目管理 6 设置代理 PHP开发时,笔者用过EditPlus3.Nodpad++.Vi.Vim和Netbeans, ...
- sprint2(第六天)
昨天休息一天,今天继续做任务. 燃尽图:
- Scrum立会报告+燃尽图(Final阶段第一次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2480 项目地址:https://coding.net/u/wuyy694 ...
- 2-Eighth Scrum Meeting20151208
任务分配 闫昊: 今日完成:和唐彬讨论研究上届的网络接口代码. 明日任务:商讨如何迁移ios代码到android平台. 唐彬: 今日完成:和闫昊讨论研究上届的网络接口代码. 明日任务:商讨如何迁移io ...
- 在数组中找出两数之和为10的所有组合(JAVA)
/*利用冒泡排序实现*/ import java.util.Scanner;public class Paixun { public static void main(String[] args) { ...