假的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. Node入门教程(2)第一章:NodeJS 概述

    Node 概述 什么是 Node Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js us ...

  2. 学习less

    什么是less?LESSCSS是一种动态样式语言,属于CSS预处理语言的一种,它使用类似CSS的语法,为CSS的赋予了动态语言的特性,如变量.继承.运算.函数等,更方便CSS的编写和维护. less哪 ...

  3. 遍历JSON

    第一种: each,不做详细说明,太常用了 第二种:我用来遍历单个组,实现前端界面绑定 for(var item in person){ alert("person中"+item+ ...

  4. 微信开发之SVN提交代码与FTP同步到apache的根目录

    SVN是协同开发的,版本控制器,就是几个人同时开发,可以提交代码到SVN服务器,这样就可以协同开发,一般是早上上班首先更新下代码,然后自己修改代码 工作一天之后,修改代码之后,下班之前,更新代码,然后 ...

  5. java排序算法之冒泡排序(Bubble Sort)

    java排序算法之冒泡排序(Bubble Sort) 原理:比较两个相邻的元素,将值大的元素交换至右端. 思路:依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一趟:首先比较第1个和第2个数 ...

  6. python入门(8)数据类型和变量

    python入门(8)数据类型和变量 数据类型 在Python中,能够直接处理的数据类型有以下几种: 整数 Python可以处理任意大小的整数,当然包括负整数,在程序中的表示方法和数学上的写法一模一样 ...

  7. Spring Security 入门(1-3-3)Spring Security - logout 退出登录

    要实现退出登录的功能我们需要在 http 元素下定义 logout 元素,这样 Spring Security 将自动为我们添加用于处理退出登录的过滤器 LogoutFilter 到 FilterCh ...

  8. windows server 2016远程桌面进去,英文系统修改语言

    由于我这边已经是改好了,以下截图来自中文版. 这边选了中文,然后点options. 选择:使该语言成为主要语言,保存. 会提示需要退出登录. 过一会重新登录,ok.

  9. UVA850【简单模拟】

    题目:解密句子.有一些被加密的句子已知一条模板翻译,判断是否可以解密,可以的话将所有句子解密. #include <stdio.h> #include<iostream> #i ...

  10. 愿奴胁下生双翼——— 详解cookie和session

    cookie和session都是基于web服务器的,不同的是cookie存储在客户端而session存储在服务器. 当用户浏览网站时,web服务器会在浏览器上存储一些当前用户的相关信息,在本地Web客 ...