假的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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. New UWP Community Toolkit - RangeSelector

    概述 前面 New UWP Community Toolkit 文章中,我们对 V2.2.0 版本的重要更新做了简单回顾,其中简单介绍了 RangeSelector,本篇我们结合代码详细讲解一下 Ra ...

  2. 使用ArrayList时代码内部发生了什么(jdk1.7)?

    前言 ArrayList(这里的ArrayList是基于jdk1.7)是在项目中经常使用的集合类,例如我们从数据库中查询出一组数据.这篇文章不去剖析它的继承和实现,只是让我们知道实例化及增删改查时它的 ...

  3. GitChat招募IT类写作作者

    GitChat是一个移动端的IT知识.技术分享平台,于2017.10和CSDN合并,成为其旗下独立品牌. 我们正在寻求有互联网基因的人来一起分享IT人员的关切,诚挚邀请您来做一次分享(让IT类文章变现 ...

  4. 《javascript设计模式与开发实践》阅读笔记(13)—— 职责链模式

    职责链模式 使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系,将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止. 书里的订单的例子 假设我们负责一个售卖手机 ...

  5. c#动态加载卸载DLL

    前段时间工作的时候遇到一个问题.就是需要每次启动程序的时候动态替换掉某个dll,所以就百度了这方面的资料.这次记录下来让自己以后可以看. 根据自己的理解,动态卸载dll需要有以下条件: 1:dll在加 ...

  6. 初次面对c++

    第一次实验 2-4源码: #include<iostream> using namespace std; int main() { int day; cin>>day; swi ...

  7. PV 动态供给 - 每天5分钟玩转 Docker 容器技术(153)

    前面的例子中,我们提前创建了 PV,然后通过 PVC 申请 PV 并在 Pod 中使用,这种方式叫做静态供给(Static Provision). 与之对应的是动态供给(Dynamical Provi ...

  8. ORACLE数据库之PL/SQL触发器、rownum、动态SQL、数据库之视图与索引

    WHEN子句说明触发约束条件.Condition为一个逻辑表达时,其中必须包含相关名称,而不能包含查询语句,也不能调用PL/SQL函数.WHEN子句指定的触发约束条件只能用在BEFORE和AFTER行 ...

  9. phpmyadmin设置编码和字符集gbk或utf8_导入中文乱码解决方法

    一.phpmyadmin设置新建数据库的默认编码为utf8编码的方法 1:新建数据库  my_db 2:使用sql语句  set character_set_server=utf8;  //设置默认新 ...

  10. PAT 1082. 射击比赛 (20)

    本题目给出的射击比赛的规则非常简单,谁打的弹洞距离靶心最近,谁就是冠军:谁差得最远,谁就是菜鸟.本题给出一系列弹洞的平面坐标(x,y),请你编写程序找出冠军和菜鸟.我们假设靶心在原点(0,0). 输入 ...