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. PHP MySQL 安全方案

     1 转义与清除转义 // 对 用户提交的数据 ' " \ 进行转义 if ( get_magic_quotes_gpc() ) { function del_magic_quotes($v ...

  2. 写了个汉字转G代码工具,无描边的那种,市面上没有类似的小软件

    学了不少G代码知识, 将公司废旧的三轴非标设备改造成了一个雕刻机,市面上的小软件不好用 网上下的软件有描边的,字体刻起来太粗,这个比较好用,看图应该都能明白吧, 就自己写了个,“少于150字的随笔不允 ...

  3. 「题目代码」P1044~P1048(Java)

    P1044 谭浩强C语言(第三版)习题5.8 import java.util.*; import java.io.*; import java.math.BigInteger; public cla ...

  4. android自动化のadb常用命令(不定期更新)

    1. adb devices 执行结果是adb为每一个设备输出以下状态信息:序列号(serialNumber) — 由adb创建的使用控制台端口号的用于唯一标识一个模拟器或手机设备的字符串,格式是 & ...

  5. 域名添加www之后(或域名后加端口)无法访问(阿里云服务器)

    当时在阿里云服务器上部署了一个api接口,通过APP调用一直很正常,突然无法访问了,然后测试调查发现,只要在域名前加上www,再通过域名加端口的方式访问的话, 显示的都是 :502 错误:还一直以为是 ...

  6. C 关键字 标示符 注释

    一 关键字 1. 什么是关键字 关键字就是C语言提供的有特殊含义的符号 也叫做"保留字" C语言一共提供了32个关键字 这些关键字都被C语言赋予了特殊含义 auto double ...

  7. VMWare Workstation新装CentOS 7无法联网解决办法

    按照这位博主的方法成功解决:http://blog.csdn.net/deniro_li/article/details/54632949

  8. CSP201412-2:Z字形扫描

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...

  9. Python3 Tkinter-OptionMenu

    1.创建 from tkinter import * root=Tk() v=StringVar() v.set('xs') om=OptionMenu(root,v,'Python','PHP',' ...

  10. 将System.Drawing.Bitmap转换为Direct2D.D2DBitmap

    最近在尝试Direct2D编程,挺好玩的. 但是有时候还是会用到GDI+来生成图片,但D2D绘图需要用到自己的D2DBitmap类. 因此需要转换,查阅了下网上的资料,写了这么一个方法: using ...