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 ;
}

B.Anton and Classes

算最大间隔。直接记录第一类第二类的最小的右端点和最大左端点。

然后答案就是第一类最大左端点-第二类最小右端点,第二类最大左端点-第一类最小右端点。

#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 ;
}

c.Anton and Fairy Tale

首先分情况,如果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 ;
}

d.Anton and School - 2

最不会的数学题,看了评论区的题解才知道怎么写……

范德蒙恒等式的证明

加个逆元就可以啦。

#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 ;
}

E.Anton and Permutation

题目是说每次交换两位置上的数,求当前逆序对的数量。

显然就是个树套树啦,不过太久没写就没写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)】题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

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

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  10. 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 题解 直接 ...

随机推荐

  1. iOS SSL Pinning 保护你的 API

    随着互联网的发展,网站全面 https 化已经越来越被重视,做为 App 开发人员,从一开始就让 API 都走 SSL 也是十分必要的.但是光这样就足够了吗? SSL 可以保护线上 API 数据不被篡 ...

  2. 「日常训练」School Marks(Codeforces Round 301 Div.2 B)

    题意与分析(CodeForces 540B) 题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲:第二分数的中位数(科目数 ...

  3. TW实习日记:第22天

    今天开发项目的还没完成的功能点,没什么难的,样式复制粘贴,JSON表单配一配,接口调一调,基本就完成了.不过中间在写后台的一些接口时,发现被自己之前写的一些方法给坑了.为什么这样说呢,因为在之前的几个 ...

  4. mpvue笔记

    简介: mpvue 修改了 Vue.js 的 runtime 和 compiler 实现,为小程序开发引入 Vue.js 开发体验 我觉得就像scss一样,写的时候方便,最后还是要转成css文件 搭建 ...

  5. 8月leetcode刷题总结

    刷题链接:https://leetcode-cn.com/explore/ 根据leetcode的探索栏目,八月份一直在上面进行刷题.发现算法题真的好难,真-计算机思维. 核心是将现实问题转化为计算机 ...

  6. 【shell 练习3】用户管理脚本(一)

    一.创建十个用户,密码为八位 [root@localhost ~]# cat UserManger02.sh #!/bin/bash . /etc/init.d/functions [ $UID -n ...

  7. LeetCode 386——字典序的第 K 小数字

    1. 题目 2. 解答 字典序排数可以看做是第一层节点分别为 1-9 的十叉树,然后我们在树上找到第 K 小的数字即可.因此,我们需要分别统计以 1-9 为根节点的每个树的节点个数.如果 K 小于当前 ...

  8. UVa 1586 - Molar Mass - ACM/ICPC Seoul 2007 - C语言

    关键在于判断数字是两位数还是单位数,其他部分没有难度. #include"stdio.h" #include"string.h" #include"c ...

  9. POJ 1921 Paper Cut(计算几何の折纸问题)

    Description Still remember those games we played in our childhood? Folding and cutting paper must be ...

  10. Memory及其controller芯片整体测试方案(下篇)

    {  第三部分  }  DDR总线的设计.调试和验证  在计算机架构中,DDR作为程序运算的动态存储器,面对如高性能计算.图形计算.移动计算.工业应用等领域的要求,发展出DDR4,以及用于图形计算的G ...