【Codeforces Round #404 (Div. 2)】题解
A. Anton and Polyhedrons
直接统计+答案就可以了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 1000
#define LL long long
using namespace std; char s[]; int main()
{
int n;
LL sum=;
scanf("%d",&n);
while (n--) {
scanf("%s",s);
if (s[]=='T') sum+=;
if (s[]=='C') sum+=;
if (s[]=='O') sum+=;
if (s[]=='D') sum+=;
if (s[]=='I') sum+=;
}
printf("%I64d\n",sum);
return ;
}
算最大间隔。直接记录第一类第二类的最小的右端点和最大左端点。
然后答案就是第一类最大左端点-第二类最小右端点,第二类最大左端点-第一类最小右端点。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 1000
#define LL long long
#define inf 1000000000
#define rep(i,l,r) for(int i=l;i<=r;i++)
using namespace std; int main()
{
int n,m,max1=-inf,min1=inf,max2=-inf,min2=inf;
scanf("%d",&n);
rep(i,,n) {
int j,k;
scanf("%d %d",&j,&k);
max1=max(max1,j);
min1=min(min1,k);
}
scanf("%d",&m);
rep(i,,m) {
int j,k;
scanf("%d %d",&j,&k);
max2=max(max2,j);
min2=min(min2,k);
}
int ans=;
ans=max(ans,max1-min2);
ans=max(ans,max2-min1);
printf("%d\n",ans);
return ;
}
首先分情况,如果n=1第一天就gg,n<=m,那第n才就gg,主要是n>=m的情况
首先前m天一定是满的,然后m+1天后每天减少等差数列颗,假设答案为x,则(1+(x-m))*(x-m)/2+x+1>=n,满足的最小的x+1就是答案,化简一下然后直接算就可以啦。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 1000
#define LL long long
#define inf 1000000000
#define rep(i,l,r) for(int i=l;i<=r;i++)
using namespace std; int main()
{
LL n,m;
scanf("%I64d %I64d",&n,&m);
if (!n) printf("0\n");
else
if (n==)
printf("1\n");
else
if (n<=m)
printf("%I64d\n",n);
else {
LL sum=m;
LL now=sqrt((n-m-)*)+;
while ((now+)*(now-)>=(n-m-)*) now--;
// printf("%I64d %I64d\n",now,now*(now*3));
sum+=now+;
printf("%I64d\n",sum);
}
return ;
}
最不会的数学题,看了评论区的题解才知道怎么写……

加个逆元就可以啦。
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define dow(i,l,r) for(int i=r;i>=l;i--)
#define maxn 400100
#define LL long long
#define mm 1000000007
using namespace std; char s[maxn];
LL f1[maxn],f2[maxn],inv[maxn]; int main()
{
scanf("%s",s);
inv[]=;
rep(i,,maxn-) inv[i]=mm-(mm/i)*inv[mm%i]%mm;
f1[]=f2[]=f1[]=f2[]=;
rep(i,,maxn-) f1[i]=f1[i-]*(LL)(i)%mm,f2[i]=f2[i-]*inv[i]%mm;
int len=strlen(s);
int l=,r=len-;
while (l<=r && s[l]==')') ++l;
while (l<=r && s[r]=='(') --r;
LL sum=;
int now1=,now2=;
rep(i,l,r) if (s[i]==')') ++now2;
rep(i,l,r) {
if (s[i]=='(' && now2) sum=(sum+f1[now1+now2]*f2[now2-]%mm*f2[now1+]%mm)%mm,now1++;
else now2--;
}
printf("%I64d\n",sum);
return ;
}
题目是说每次交换两位置上的数,求当前逆序对的数量。
显然就是个树套树啦,不过太久没写就没写23333。树状数组套权值线段树。权值线段树用数组写开了20000000的大小才给过,看来要学习指针写法(p党的残念)。另外还得学会cdq分治的写法。
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define dow(i,l,r) for(int i=r;i>=l;i--)
#define maxn 400100
#define maxm 20001000
#define LL long long
#define mm 1000000007
using namespace std; int size[maxm],lson[maxm],rson[maxm],num[maxn],bit[maxn],n,total; int addson() {return ++total;}
int lowbit(int x) {return x&(-x);} void add(int &x,int l,int r,int y,int z)
{
if (!x) x=addson();
size[x]+=z;
if (l==r) return;
int mid=(l+r)>>;
if (y<=mid) add(lson[x],l,mid,y,z);
else
add(rson[x],mid+,r,y,z);
} int ask(int x,int l,int r,int y)
{
if (!x) return ;
if (l==r) return size[x];
int mid=(l+r)>>;
if (y<=mid) return ask(lson[x],l,mid,y);
else
return size[lson[x]]+ask(rson[x],mid+,r,y);
} LL bigask(int x,int y)
{
LL now=;
while (x) {
now+=ask(bit[x],,n,y);
x-=lowbit(x);
}
return now;
} void bigadd(int x,int y,int z)
{
while (x<=n) {
add(bit[x],,n,y,z);
x+=lowbit(x);
}
} int main()
{
int m;
scanf("%d %d",&n,&m);
LL sum=;
rep(i,,n) bigadd(i,num[i]=i,);
while (m--) {
int l,r;
scanf("%d %d",&l,&r);
if (l==r) {
printf("%I64d\n",sum);
continue;
}
if (l>r) swap(l,r);
if (r-l>) {
sum-=*(bigask(r-,num[l])-bigask(l,num[l]));
sum+=*(bigask(r-,num[r])-bigask(l,num[r]));
}
if (num[l]<num[r]) ++sum;else --sum;
printf("%I64d\n",sum);
bigadd(l,num[l],-);
bigadd(l,num[r],);
bigadd(r,num[r],-);
bigadd(r,num[l],);
swap(num[l],num[r]);
}
return ;
}
【Codeforces Round #404 (Div. 2)】题解的更多相关文章
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
随机推荐
- .net core mvc 模型绑定 之 json and urlencoded
.net core mvc 模型绑定, FromQuery,对应 url 中的 urlencoded string ("?key1=value1&key2=value2") ...
- java nio之channel
一.通道(Channel):由 java.nio.channels 包定义的.Channel 表示 IO 源与目标打开的连接.Channel 类似于传统的“流”.只不过 Channel本身不能直接访问 ...
- redis 学习笔记三
一.redis 复制 数据库复制指的是发生在不同数据库实例之间,单向的信息传播的行为,通常由被复制方和复制方组成,被复制方和复制方之间建立网络连接,复制方式通常为被复制方主动将数据发送到复制方,复制方 ...
- WEB网站测试心得整理
一.输入框: 1.正常的字母/文字/数字(正常流程的测试): 2.重复提交(输入内容后,重复点击提交按钮): 3.纯异常字符/正常输入夹杂异常字符(!@#¥%……&**等等): 4.长度限制( ...
- 【转】Haml 这货是啥? 附参考
Haml是一种用来描述任何XHTML web document的标记语言,它是干净,简单的.而且也不用内嵌代码.Haml的职能就是替代那些内嵌代码的page page templating syste ...
- QT打开文件路径中含有中文和空格问题
使用qt-mingw版做的软件,发给客户以后说工作不正常,配置文件无法打开,或者加载数据文件不正常.远程查看以后,发现客户经常将程序放置在中文带空格的路径下,导致文件打开不正常.所以最近想在程序上解决 ...
- C#通过gridview导出excel
[CustomAuthorize] public FileResult ExportQuestionCenterExcel(SearchBaseQuestion search) ...
- HADOOP (十一).安装hbase
下载安装包并解压设置hbase环境变量配置hbase-site.xml启动hbase检测hbase启动情况测试hbase shell 下载安装包并解压 https://mirrors.tuna.tsi ...
- Java容器之Set接口
Set 接口: 1. Set 接口是 Collection 的子接口,Set 接口没有提供额外的方法,但实现 Set 接口的容器类中的元素是没有顺序的,且不可以重复: 2. Set 容器可以与数学中的 ...
- YaoLingJump开发者日志(五)V1.0版本完成
跳跃吧瑶玲下载连接 官网下载 百度网盘下载 提取码:apx9 介绍 总算完成V1.0版本了,下面来简单地介绍一下吧! 打开游戏,最开始会进入到"主界面". 右上角的按钮 ...