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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 微信小程序如何动态增删class类名
简述 由于微信小程序开发不同于以往的普通web开发, 因此无法通过js获取wxml文件的dom结构, 因此从js上直接添加一个类名应该不可能了. 可是我们可以通过微信小程序数据绑定以及view标签的& ...
- 使用Python3爬虫抓取网页来下载小说
很多时候想看小说但是在网页上找不到资源,即使找到了资源也没有提供下载,小说当然是下载下来用手机看才爽快啦! 于是程序员的思维出来了,不能下载我就直接用爬虫把各个章节爬下来,存入一个txt文件中,这样, ...
- docker实践
我的docker 学习笔记2 ps axf docker run -d cyf:sshd /usr/sbin -D docker ps docker-enter.sh 686 ps axf ...
- 【深度学习】深入理解优化器Optimizer算法(BGD、SGD、MBGD、Momentum、NAG、Adagrad、Adadelta、RMSprop、Adam)
在机器学习.深度学习中使用的优化算法除了常见的梯度下降,还有 Adadelta,Adagrad,RMSProp 等几种优化器,都是什么呢,又该怎么选择呢? 在 Sebastian Ruder 的这篇论 ...
- python爬虫动态html selenium.webdriver
python爬虫:利用selenium.webdriver获取渲染之后的页面代码! 1 首先要下载浏览器驱动: 常用的是chromedriver 和phantomjs chromedirver下载地址 ...
- Hive函数:LAG,LEAD,FIRST_VALUE,LAST_VALUE
参考自大数据田地:http://lxw1234.com/archives/2015/04/190.htm 测试数据准备: create external table test_data ( cooki ...
- hdu1022 Train Problem I---模拟栈
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 车的进出站问题,先给出N个火车,再按序列一的方式进站,判断能否以序列二的方式出站,若 ...
- 屏幕上两点画线+DDALine算法
编译环境VS2017+EasyX #include "stdafx.h" #include"graphics.h" void DDALine(int x0, i ...
- 完成 bass 库的频谱显示效果图
效果如图所示,比 bass 官方自带的例子效果要好那么一点点(峰值有滞留)...
- sumo快速运行简单仿真实例详细教程
本文旨在让大家快速的了解sumo,并给出运行一个简单的sumo的例子的教程,进而了解基本sumo工程的架构,使大家对该软件产生兴趣并持续学习下去,刚开始学习仿真的确枯燥,项目"跑起来&quo ...