Codeforces #Round 785(Div.2)
假的div2 C题没事写什么公式被卡精度了,掉分了gg
---------------------------------------------------
A....几个每个字符串预先给好一个代表的值,给n个字符串,求和。
题解:手速题。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
#define ll long long
#define INF 2000000000
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
} map<string,int> mp;
int n;
ll ans=;
string st; int main()
{
n=read();mp["Tetrahedron"]=;
mp["Cube"]=;
mp["Octahedron"]=;
mp["Dodecahedron"]=;
mp["Icosahedron"]=;
for(int i=;i<=n;i++)
cin>>st,ans+=mp[st];
cout<<ans;
return ;
}
B.有两种课,每种课都有很多节,每节课有一段时间l..r,你要从两种课中都选一节,使得中间的休息时间最长。
题解:两边都分别记一下最小值,最大值。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
#define ll long long
#define INF 2000000000
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
} int mx1,mx2,mn1=INF,mn2=INF;
int n,m,ans=; int main()
{
n=read();
for(int i=;i<=n;i++)
{
int l=read();int r=read();
mx1=max(mx1,l);mn1=min(mn1,r);
}
m=read();
for(int i=;i<=m;i++)
{
int l=read();int r=read();
mx2=max(mx2,l);mn2=min(mn2,r);
}
ans=max(ans,max(mx1-mn2,mx2-mn1));
cout<<ans;
return ;
}
C.有一个大小为n的粮仓,一开始是满的,每天都会运来m的粮食,但是不能超过大小上限,然后运来后会有不速之客来吃,第i天吃掉i的粮食,求第几天粮食被吃完了。
n,m<=10^18
正确解法:二分答案,等差数列求和
我的错误解法:解一元二次方程,结果用了double被卡精度,FST了,改成long double 就过了.... 心累。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
#include<cmath>
#define ll unsigned long long
#define double long double
#define INF 2000000000
#define eps 1e-8
using namespace std;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
} ll n,m,size; int main()
{
n=read();m=read();
if(n<=m)cout<<n;
else
{
double mm=sqrt((double)n*2.0-(double)m*2.00+0.25)-0.5;
m+=(ll)ceil(mm);
cout<<m;
}
return ;
}
D.给定一个长度为n的括号序列,求特殊的括号子序列的数量。特殊的是指,前一半是(,后一半是) n<=200000
左边有n个左括号,右边有m个右括号,我们为了去重要求一定选最右的哪个左括号,这是侯答案数量是∑C(n,k-1)*C(m,k) k=1..min(n,m)
然后我们会发现这个式子就等于C(n+m-1,m-1),所以预处理好阶乘和逆元,就可以算啦。
复杂度O(n)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
#include<cmath>
#define ll long long
#define INF 2000000000
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
} int n;
char s[];
ll p[],l[];
int num1=,num2=;
ll ans=; ll work(int n,int c)
{
return p[n]*l[c]%mod*l[n-c]%mod;
} int main()
{
scanf("%s",s+);n=strlen(s+);
p[]=l[]=l[]=;
for(int i=;i<=;i++)p[i]=p[i-]*i%mod;
for(int i=;i<=;i++)l[i]=(mod-mod/i)*l[mod%i]%mod;
for(int i=;i<=;i++)l[i]=l[i]*l[i-]%mod;
for(int i=;i<=n;i++)num2+=(s[i]==')');
for(int i=;i<=n;i++)
{
if(s[i]==')')num2--;
else
{num1++;ans=(ans+work(num1+num2-,num2-))%mod;}
}
cout<<ans;
return ;
}
E.给定一个1-n的全排列,一开始是1到n摆放。q个操作,每次交换一对数,然后要求交换后的逆序对数量。n<=200000,q<=50000 题目有4s
1.分块+树状数组。复杂度应该是n^1.5*logn
2.树状数组套平衡树.....(ditoly真的强,几下就切完了)复杂度nlog^2n
分块 2308ms
#include<iostream>
#include<cstdio>
#include<cmath>
#define ll long long
#define MAXN 200005
#define MAXB 455
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
} int n,m,size;
ll ans=;
int c[MAXB][MAXN],s[MAXN],block[MAXN]; void renew(int num,int x,int ad)
{
for(;x<=n;x+=x&(-x))
c[num][x]+=ad;
} int query(int num,int x)
{
int sum=;
for(;x;x-=x&(-x))
sum+=c[num][x];
return sum;
} ll solve(int l,int r,int num)
{
if(l>r)return ;
int sum=;
if(block[l]==block[r])
{
for(register int i=l;i<=r;i++)sum+=(s[i]<num);
return(ll)sum;
}
for(register int i=block[l]+;i<block[r];i++)
sum+=query(i,num);
if(block[l-]!=block[l])sum+=query(block[l],num);
else for(register int i=l;block[i]==block[l]&&i<=r;i++)sum+=(s[i]<num);
if(block[l]==block[r]) return (ll)sum;
if(block[r+]!=block[r])sum+=query(block[r],num);
else for(register int i=r;block[i]==block[r]&&i>=l;i--)sum+=(s[i]<num);
return(ll)sum;
} int main()
{
n=read();m=read();size=sqrt(n);
for(int i=;i<=n;i++)block[i]=(i-)/size+;
for(int i=;i<=n;i++)s[i]=i,renew(block[i],i,);
for(register int i=;i<=m;i++)
{
int u=read(),v=read();if(u>v)swap(u,v);
if(u==v){printf("%lld\n",ans);continue;}
if(u!=v-)
{
ans+=*solve(u+,v-,s[v]);
ans-=*solve(u+,v-,s[u]);
}
renew(block[u],s[u],-);renew(block[u],s[v],);
renew(block[v],s[v],-);renew(block[v],s[u],);
swap(s[u],s[v]);
// cout<<ans;
if(s[u]>s[v])ans++;else ans--;
printf("%lld\n",ans);
}
return ;
}
做法2以后补
Codeforces #Round 785(Div.2)的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 超绚丽CSS3多色彩发光立方体旋转动画
CSS3添加了几个动画效果的属性,通过设置这些属性,可以做出一些简单的动画效果而不需要再去借助JavaScript.css3动画的属性主要分为三类:transform.transition以及anim ...
- Microsoft Soft SQL Server 大数据----分区表性能测试
分区表 MSSQL有一个大数据储存方案,可以提高效率那就是分区表. 使用起来跟普通表没有区别.至于具体原理自己度娘吧. 真正性能的提高,是依赖于硬件的加入.也是就说,当把一个表设置成分区表,每一个分区 ...
- 电子称DIY(贴应变片+写代码)
第一步.应变片介绍 ---------------------------------------------------------------------------------------- ...
- VS 提示:请考虑使用 app.config 将程序集“XXX”从版本“XX”重新映射到版本“XX”,以解决冲突并消除警告。
具体提示如下: 请考虑使用 app.config 将程序集"System.Web.Http.WebHost, Culture=neutral, PublicKeyToken=31bf3856 ...
- python全栈开发-常用模块的一些应用
一.random模块详解 1.概述 首先我们看到这个单词是随机的意思,他在python中的主要用于一些随机数,或者需要写一些随机数的代码,下面我们就来整理他的一些用法 2.常用方法 1. random ...
- Python内置函数(20)——hex
英文文档: hex(x) Convert an integer number to a lowercase hexadecimal string prefixed with "0x" ...
- github入门:设置添加ssh key<转>
GitHub是个分布式的版本控制库.github通过git使用,可以方便的记录代码版本. 通过github可以学习优秀的代码,可以改进提交其他项目中的bug,借助社区力量促进软件优化完善. 国内外大量 ...
- apigw鉴权分析(1-3)百度 AI - 鉴权方式分析
http://ai.baidu.com/docs#/Begin/top 一.访问入口 二.鉴权方式分析 1.鉴权认证方式一 - access_token - 针对HTTP API调用者 2.鉴权认证方 ...
- Python入门之函数的形式参数与实参/参数的具体使用方法
本篇目录: 一. 函数参数之形式参数与实参 二. 函数参数的具体使用 #1.位置参数:按照从左到右的顺序定义的参数 位置形参:必选参数 位置实参:按照位置给形参传值 #2.关键字参数:按照key=va ...
- 给定了经纬度的一张my_latlng表,和一个my_grid表,怎么实现my_latlng表回mygrid中的id?
场景: 假设我们拥有一个拥有了一系列经纬度的表my_latlng(lat string,lng string)表,还有一张给定的栅格表my_grid(gridid bigint,centerlng d ...