//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. 修改response,报错Cannot call getWriter(), getOutputStream() already called

    往response里面改数据,然后系统报这个错 此时直接return null即可解决 但是,要想返回相应的页面呢? 可以直接在response里设置返回的页面

  2. web.config文件executionTimeout的单位

      executionTimeout:表示允许执行请求的最大时间限制,单位为秒

  3. EF增删查改加执行存储过程和sql语句,多种方法汇总

    ActionUrl c = new ActionUrl() { ActionName="test", RequestUrl="/123/123", SubTim ...

  4. agc007B - Construct Sequences(构造)

    题意 题目链接 给出一个$1-N$的排列$P$,构造两个数组$a, b$满足 Sol 发现我的水平也就是能做一做0-699的题.... 直接构造两个等差数列$a, b$,公差为$20000$ 然后从小 ...

  5. java 千分位的添加和去除

    转至:http://blog.sina.com.cn/s/blog_8f99a1640102v1xh.html 将一个数字转换为有千分位的格式: NumberFormat numberFormat1  ...

  6. 【extjs6学习笔记】1.14 初始: ViewModel

    ViewModel是一个管理特定UI组件数据的类. 可以将其视为特定视图的记录容器. 它支持与UI组件的双向数据绑定,只要用户在视图中更改数据,它具有最新的副本. 与模型不同,它不能包含代理,因此它不 ...

  7. 逐步解读String类(一)

    一句题外话 面试刚入行的Java新手,侧重基础知识:面试有多年工作经验的老鸟,多侧重对具体问题的解决策略. 从一类面试题说起 考察刚入行菜鸟对基础知识的掌握程度,面试官提出关于String类的内容挺常 ...

  8. System Center Configuration Manager 2016 必要条件准备篇(Part1)

    步骤4.创建系统管理容器 SCCM 2016 配置管理系列(Part 1- 4) 介绍AD01上配置了Active Directory域服务(ADDS),然后将Configuration Manag ...

  9. 基于PowerShell的Lync Server管理 使用C# 之 Telephony 功能 查看 /修改

    本以为这个属性可以在用户信息中直接反应出来,但是看了好几遍还是没找到这个属性名称 这个功能没有在get-User 的结果中直接反映出来 但是可以通过 Property 查找单个选项 如: Get-Cs ...

  10. linux 命令——4 mkdir (转)

    linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录... 2.命令 ...