【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 题解 直接 ...
随机推荐
- mysql主从集群搭建;(集群复制数据)
1.搭建mysql 5.7环境chown mysql:mysql -R /data/groupadd mysqluseradd -g mysql mysql yum install numactlrp ...
- Intellij打包jar文件,“java.lang.SecurityException: Invalid signature file digest for Manifest main attrib
下面是使用Intellij 打包jar文件的步骤,之后会有运行jar文件时遇到的错误. 打包完成. ================================================== ...
- wamp报错SCREAM:Error suppression ignored for
问题:SCREAM:Error suppression ignored for 解决: 在php.ini最下面加入scream.enabled = Off http://stackoverflow.c ...
- 【vps搬家】--总结--费元星
20150310 费元星 稍微玩VPS/服务器比较久的站长手中应该不止一台VPS,我们会有多台机器之间的相互使用.比如可能会遇到的是数据传输,我们传统的做法是先用FTP下载数据A到本地,然后再到本地 ...
- Mysql 8.0.* zip版本 windows安装
一,MySQL8.0.*zip版本安装步骤. 1,下载 https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.15-winx64.zip 注现 ...
- ElasticSearch-Java-low-level-rest-client官方文档翻译
人肉翻译,非谷歌机翻,部分地方添加了个人的理解,并做了分割,如有错误请在评论指出.转载请指明原链接,尊重个人劳动成果. High-Level-Rest-Client基于Low-Level ...
- Selenium(Python)页面对象+数据驱动测试框架
整个工程的目录结构: 常用方法类: class SeleniumMethod(object): # 封装Selenium常用方法 def __init__(self, driver): self.dr ...
- node事件循环
Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用,并处理并发. Node.j ...
- 如何处理 jQuery $(window).resize() 中的方法被多次执行的小问题
引言: 估计很多同志们在编写浏览器resize()的方法时,都会遇到这样的情况: 当拖动浏览器的边角时,页面中的一些效果随浏览器大小的改变而触发,这一过程开始到结束,resize() 中的方法被执行了 ...
- ubuntu networking 与 network-manager
刚遇到的坑,因为操作不当导致网络中断,于是手动配置了/etc/network/interfaces , 修复了系统之后发现ubuntu-desktop中的有线链接不见了,百度了一下说是networki ...