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. LeetCode: 56. Merge Intervals(Medium)

    1. 原题链接 https://leetcode.com/problems/merge-intervals/description/ 2. 题目要求 给定一个Interval对象集合,然后对重叠的区域 ...

  2. CLR via C#读书笔记二:类型基础

    1.CLR允许将对象转换为它的(实际)类型或者它的任何基类型. 2.is操作符检测对象是否兼容于指定类型,is操作符永远不抛出异常. 3.as操作符返回对同一个对象的非null引用.如果对象不兼容,a ...

  3. libevent学习六(Connect listeners )

      创建与释放 //backlog需要查询平台说明,在linux2.2以后 backlog就变成了已完成连接但未accept的队列的最大值(原来是处于syn状态的,现在换成sysctl 控制的参数tc ...

  4. 即刻开始使用Kotlin开发Android的12个原因(KAD 30)

    作者:Antonio Leiva 时间:Jul, 11, 2017 原文链接:https://antonioleiva.com/reasons-kotlin-android/ 这组文章已到最后了,它们 ...

  5. C 计算时间差

    #include <stdio.h>int main(){ //新建四个变量 la 代表小时 kc代表时间 int l,k,a,c; //输入 两个时间 scanf("%d %d ...

  6. 2018(容斥定理 HDU6286)

    2018 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. PAT-甲级解题目录

    PAT甲级题目:点这里 pat解题列表 题号 标题 题目类型  10001 1001 A+B Format (20 分)  字符串处理  1003 1003 Emergency (25 分) 最短路径 ...

  8. Python3 Tkinter-Radionbutton

    1.创建单选按钮 from tkinter import * root=Tk() Radiobutton(root,text='b1').pack() Radiobutton(root,text='b ...

  9. python中spilt()函数和os.path.spilt()函数区别

    Python中有split()和os.path.split()两个函数: split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表. os.path.split():将文件 ...

  10. selenium实现文件上传方法汇总(AutoIt、win32GUI、sengkeys)---基于python

    在使用selenium进行UI自动化测试时,经常会遇到一个关于本地文件上传的问题,解决此问题一般分两种情况: 1. 元素标签为input 2.非input型上传 下面我们分别对着两种情况进行实例分析 ...