//B. Delete from the Left
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=2e5+;
char a[N],b[N];
int main()
{
scanf("%s%s",a,b);
int lena=strlen(a);
int lenb=strlen(b);
int i=lena-,j=lenb-;
int sum=;
while(a[i]==b[j]&&i>=&&j>=)//s[-1]与p[-1]是不确定的
{ //因此加上i>=0&&j>=0 和下面的D题相似
sum++;
i--,j--;
}
printf("%d\n",lena+lenb-*sum);
return ;
}
 //C. Summarize to the Power of Two
/*

2^(n-1)   x   2^n  2^(n+1)

因为x<2^n,所以2*x<2^(n+1),那么x+y(0<x<y)一定位于

2^(n-1)和2^(n+1)之间。若x+y为2的指数幂,那么必定是2^n.

*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=;
ll n;
ll a[N];
map<ll,ll>mp;
set<ll>s;
int main()
{
scanf("%lld",&n);
for(int i=;i<n;i++)
{
scanf("%lld",&a[i]);
mp[a[i]]++;
}
sort(a,a+n);//为了二分
s.clear();
for(int i=;i<n;i++)
{
ll ans=log2(a[i]);
ll ret=pow(,ans+)-a[i];
if(binary_search(a,a+i,ret))
{ //二分查找[) ,不会取到自己
s.insert(a[i]);
s.insert(ret);//set可以去重
}
}
ll cnt=;
for(auto it=s.begin();it!=s.end();it++){
cnt+=mp[*it];
}
printf("%lld\n",n-cnt);
return ;
}
/*
下面是简单的二分查找函数
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
ll m;
while(~scanf("%lld",&m)){
if(binary_search(a+1,a+4,m)){//[)
cout<<"yes\n";
}
else{
cout<<"no\n";
}
}
return 0;
} 5
1 2 3 4 5
1
no
2
yes
3
yes
4
yes
5
no */ //C. Summarize to the Power of Two
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
ll n;
map<ll,ll>mp;
const int M=1.3e5+;
ll a[M];
int main()
{
scanf("%lld",&n);
for(ll i=;i<n;i++)
{
scanf("%lld",&a[i]);
mp[a[i]]++;
}
ll ans=;
bool flag;
for(ll i=;i<n;i++)
{
flag=;
mp[a[i]]--;//将a[i]先取出
//为了避免a[i]与(1<<j)-a[i]是同位置
//当然也有其他的方法
//if(mp[(1<<j)-a[i]]==1&&a[i]!=(1<<j)-a[i]||mp[(1<<j)-a[i]]>1)
//出现多次,可以互相替换,1次只要两者不等,就一定不是同一位置
//不相等一定不是同位置
for(int j=;j<=;j++)
{
if(mp[(<<j)-a[i]])
{
flag=;
break;
}
}
if(!flag)
ans++;
mp[a[i]]++;//再恢复
}
printf("%lld\n",ans);
return ;
}
 ////D. Polycarp and Div 3
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=2e5+;
ll dp[N];
char s[N];
int main()
{
scanf("%s",s+);
/*
if(s[1]=='1'&&s[2]=='1'){
if(strlen(s+1)==2){
printf("0\n");
return 0;
}
}
*/ int lens=strlen(s+);
memset(dp,,sizeof(dp));
if((s[]-'')%==){
dp[]=;
}
//int i,j,k,sum;
for( int i=;i<=lens;i++)
{
dp[i]=dp[i-];
//cout<<"iii"<<i<<endl;
for( int j=i-;j>=;j--)//起初没加j>=0
{ //如dp[-1]=dp[0]=dp[1]=0 。数组的负下标问题
//可能令最终的结果有问题,也会时间更长
if(dp[j]!=dp[i-])
break;
if(s[j+]==''&&i-j>)
continue;
//cout<<dp[j]<<" "<<dp[i-1]<<endl;
int sum=;
for(int k=i;k>=j+;k--)
{
sum=(sum+(s[k]-''))%;
}
//cout<<"sum "<<sum<<endl;
if(sum==)
{
dp[i]=max(dp[i],dp[j]+);
} }
//cout<<i<<" "<<dp[i]<<endl;
}
printf("%lld\n",dp[lens]);
return ;
} //D. Polycarp and Div 3
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=2e5+;
int main()
{
char s[N];
scanf("%s",s);
int sum=,cnt=,tmp;
int ans=;
for(int i=;s[i];i++)
{
tmp=(s[i]-'')%;
sum+=tmp;
cnt++;
if(tmp==||sum%==||cnt==)
{
ans++;
sum=cnt=;
}
}
printf("%d\n",ans);
return ;
}
 // E1 - Median on Segments (Permutations Edition)
//区间内大于m的数的个数-小于m的数的个数(sum)==0or1
//在m出现之前依次记录sum,用map存储每个sum出现的个数
//等到m出现后,每当遇到一个sum,ans+=(sum出现的次数)+(sum-1出现的次数)
//sum sum 区间内大于m的数的个数-小于m的数的个数==0
//sum(前面) sum-1(后面) 区间内大于m的数的个数-小于m的数的个数==1
//m出现后不再增加sum出现的次数,因为那些区间不会包含m
//符合条件的区间一定要包含m
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=2e5+;
int n,m,a[N];
map<ll,ll>mp;
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
ll sum=;
mp[]=;
bool flag=;
ll ans=;
for(int i=;i<n;i++)
{
if(a[i]<m)
sum--;
else if(a[i]>m)
sum++;
if(a[i]==m)
flag=;
if(flag){
ans+=mp[sum]+mp[sum-];
}
else{
mp[sum]++;
}
}
printf("%lld\n",ans);
return ;
}

Codeforces Round #496 (Div. 3) ABCDE1的更多相关文章

  1. CodeForces -Codeforces Round #496 (Div. 3) E2. Median on Segments (General Case Edition)

    参考:http://www.cnblogs.com/widsom/p/9290269.html 传送门:http://codeforces.com/contest/1005/problem/E2 题意 ...

  2. Codeforces Round #496 (Div. 3)

    一如既往地四题...好久没切了 有点犯困了明显脑子感觉不够灵活. 为了熟练度还是用java写的,,,导致观赏性很差...我好不容易拉了个队友一起切结果过掉a就tm挂机了!!! A题竟然卡了,,,用了十 ...

  3. Codeforces Round #496 (Div. 3 ) E1. Median on Segments (Permutations Edition)(中位数计数)

    E1. Median on Segments (Permutations Edition) time limit per test 3 seconds memory limit per test 25 ...

  4. Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths

    F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...

  5. Codeforces Round #496 (Div. 3) E2 - Median on Segments (General Case Edition)

    E2 - Median on Segments (General Case Edition) 题目大意:给你一个数组,求以m为中位数的区间个数. 思路:很巧秒的转换,我们把<= m 数记为1, ...

  6. Codeforces Round #496 (Div. 3) E1. Median on Segments (Permutations Edition) (中位数,思维)

    题意:给你一个数组,求有多少子数组的中位数等于\(m\).(若元素个数为偶数,取中间靠左的为中位数). 题解:由中位数的定义我们知道:若数组中\(<m\)的数有\(x\)个,\(>m\)的 ...

  7. Codeforces Round #496 (Div. 3) D. Polycarp and Div 3 (数论)

    题意:给你一个巨长无比的数,你可以将这个数划成任意多个部分,求这些部分中最多有多少个能被\(3\)整除. 题解:首先我们遍历累加每个位置的数字,如果某一位数或者累加和能被\(3\)整除(基础知识,不会 ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. 字符串实现Base64加密/解密

    有时候需要对字符串进行加密,不以明文显示,可以使用此方法,比如对URL的参数加密 using System; using System.Collections.Generic; using Syste ...

  2. usb-host一步一步学(二)安卓在usb-host模式下列出当前连接的usb设备

    之前写了一个简单的例子usb-host一步一步学(一)安卓在usb-host模式下列出当前连接的usb设备,下面的这个例子是获取各种usb设备.usb接口以及usb连接点(endpoint) 正如上一 ...

  3. springboot 学习笔记(六)

    (六)springboot整合activemq 1.现下载activemq,下载链接:http://activemq.apache.org/download.html,windows系统解压后进入bi ...

  4. Fiddler 抓包工具总结(转)

    Fiddler 抓包工具总结   阅读目录 1. Fiddler 抓包简介 1). 字段说明 2). Statistics 请求的性能数据分析 3). Inspectors 查看数据内容 4). Au ...

  5. java 基础 04 循环结构 一维数组

    内容: (1)循环结构 (2)一维数组 1.循环结构 1.1for循环 (1)语法格式 for(初始化表达式1;条件表达式2;修改初始化表达式3){ 循环体; } (2)执行流程 执行初始化表达式 = ...

  6. 从零开始的全栈工程师——js篇2.11(原型)

    原型 原型分析 1.每个 函数数据类型(普通函数,类)都有一个prototype属性 并且这个属性是一个对象数据类型2.每个Prototype上都有一个constructor属性 并且这个属性值是当前 ...

  7. 扩展(spread)/收集(rest)运算符

    一.扩展运算符(spread)    场景:使用在数组之前. 作用:将一个数组转为用逗号分隔的参数序列 举例1:数组之前 function foo(x, y, z){ console.log(x, y ...

  8. lintcode五道题

    1.二叉树的最大深度 最大深度为根节点到最远叶子节点的距离为最大深度,于是可以先找到根节点到叶子节点最大的距离,过程就可以分为左子树 和右子树分别进行来求左.右子树的最大深度lh=height(roo ...

  9. ubuntu常见错误

    ubuntu常见错误--Could not get lock /var/lib/dpkg/lock解决 ubuntu常见错误--Could not get lock /var/lib/dpkg/loc ...

  10. Python参数基础

    Python参数基础 位置参数 ​ 通过位置进行匹配,把参数值传递给函数头部的参数名称,顺序从左到右 关键字参数 ​ 调用的时候使用参数的变量名,采用name=value的形式 默认参数 ​ 为没有传 ...