//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. .net中Response.End() 和Response.Redirect("http://dotnet.aspx.cc");

    问:什么情况下需要Response.End()语句,加这句有什么好处 答: 首先你要理解Response.End()的意思,它的意思是终止执行下面的语句!但有时不加和加上都一样,但还要加上好,为什么呢 ...

  2. ElasticSearch2.2.0安装(win7)

    ElasticSearch2.2.0必须在jdk1.7上才可以启动起来哦. 一.ElasticSearch2.2.0安装 1.下载ElasticSearch2.2.0安装包 https://downl ...

  3. AnyCAD在医疗中的应用

    void addPoint(List<float> buffer, Vector3 pt) { buffer.Add((float)pt.X); buffer.Add((float)pt. ...

  4. Laravel事件监听器listener与事件订阅者Subscriber的区别

    其实就一句话: Each event can have multiple listeners, but a listener can't listen to more than a single ev ...

  5. MATLAB之数学建模:深圳市生活垃圾处理社会总成本分析

    MATLAB之数学建模:深圳市生活垃圾处理社会总成本分析 注:MATLAB版本--2016a,作图分析部分见<MATLAB之折线图.柱状图.饼图以及常用绘图技巧> 一.现状模式下的模型 % ...

  6. FusionCharts可使用JavaScript渲染iPhone/iPod/iPad图表

    FusionCharts使用JavaScript: FusionCharts允许用户创建建立JavaScript图表(也就是web上的HTML5 /Canvas图表).这个特性允许用户在不支持Flas ...

  7. [转]vim 快捷键整理

    Linux中vim编辑器的功能非常强大,许多常用快捷键用起来非常方便,这里将我学vim入门时学的一些常用的快捷键分享给大家一下,希望可以帮助你们.  原文地址:http://blog.csdn.net ...

  8. 编译出freeswitch的java调用的 jar和so

    假设freeswitch 源码路径为 /usr/local/src/freeswitch 1. cd /usr/local/src/freeswitch(源代码的根目录) 执行./configure, ...

  9. meterpreter > screenshot

    meterpreter > screenshotScreenshot saved to: /opt/metasploit/msf3/wLafQYhx.jpegmeterpreter > / ...

  10. Qt安装教程

    一.Qt下载 官网下载链接http://download.qt.io/archive/qt/,下载最新版 5.10 官网的下载网站有的时候可能会抽风,也可以选择国内的镜像下载源http://mirro ...