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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- Flask 学习 十五 性能
记录影响性能的数据库查询 app/main/views.py from flask_sqlalchemy import get_debug_queries @main.after_app_reques ...
- JAVA中最容易让人忽视的基础。
可能很多找编程工作的人在面试的时候都有这种感受,去到一个公司填写面试试题的时候,多数人往往死在比较基础的知识点上.不要奇怪,事实就是如此一般来说,大多数公司给出的基础题大概有122道,代码题19道左右 ...
- MySQL搭建主从数据库 实现读写分离
首先声明,实际生产中,网站为了提高用户体验,性能等,将数据库实现读写分离是有必要的,我们让主数据库去写入数据,然后当用户查询的时候,然后在从数据库读取数据,故能减轻数据库的压力,实现良好的用户体验! ...
- 自制 h5 音乐播放器 可搜索
闲言碎语: 有好几天没有发表博客了,这也是因为一直开发音乐和完善我的博客项目,好不容易抽出时间总结一下这几天所做的东西,笔试又不断通知,实则匆忙 今天难得逃了一次课,就趁这时间,该写写就写写吧~~ 进 ...
- Spring+Hibernate+Struts(SSH)框架整合
SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...
- 使用C#开发Android应用之WebApp
近段时间了解了一下VS2017开发安卓应用的一些技术,特地把C#开发WebApp的一些过程记录下来, 欢迎大家一起指教.讨论,废话少说,是时候开始表演真正的技术了.. 1.新建空白Android应用 ...
- LeetCode & Q169-Majority Element-Easy
Array Divide and Conquer Bit Manipulation Description: Given an array of size n, find the majority e ...
- wpf研究之道——datagrid控件分页
这是我们的datagrid分页效果图,有上一页,下一页,可以跳到任何一页.当页码比较多的时候,只显示几页,其余用点点,界面实现如下: <!--分页--> <StackPanel Or ...
- Python内置函数(4)——min
英文文档: min(iterable, *[, key, default]) min(arg1, arg2, *args[, key]) Return the smallest item in an ...
- java 数组排序方法整理,简单易懂,
1.快速排序:首先是最简单的Array.sort,直接进行排序: public static void main(String[] args) { int[] arr = {4,3,5,1,7,9,3 ...