//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. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  2. PHP面向对象编程一

    php面向对象编程(一)   类与对象关系: 类就像一个人类的群体 我们从类中实例化一个对象 就像是制定一个人. 面向对象程序的单位就是对象,但对象又是通过类的实例化出来的,所以我们首先要做的就是如何 ...

  3. Pod管理的iOS项目修改工程名

    声明:本文大部分内容来自于以下网址,其余的部分是自己尝试的总结和补充. http://www.jianshu.com/p/5f088acecf64 完整修改iOS工程名1 http://www.cnb ...

  4. 金三银四面试季节之Java 核心面试技术点 - JVM 小结

    原文:https://github.com/linsheng9731/notebook/blob/master/java/JVM.md 描述一下 JVM 的内存区域 程序计数器(PC,Program ...

  5. Thymeleaf的模板使用介绍

    参考网址: https://blog.csdn.net/hry2015/article/details/73476973 先定义一个html文件, 如下: 文件路径: templates/templa ...

  6. 关于Mybatis的pagehelper使用遇到的坑

    参考博客: https://blog.csdn.net/wzyxdwll/article/details/66473466 下面给出pagehelp使用的配置, 在springmvc中的配置: 下面是 ...

  7. 使用后台程序的第一个表单Form

    参考手册:http://www.yiichina.com/doc/guide/2.0/start-forms 1.创建模型:advanced\backend\models\moxing.php 此模型 ...

  8. openstack RuntimeError: Unable to create a new session key. It is likely that the cache

    [Mon Apr 15 01:02:31.654247 2019] [:error] [pid 19433:tid 139790082479872] Login successful for user ...

  9. SVN .a文件丢失问题

    只需2张图 这样就ok 了

  10. [超详细] Python3爬取豆瓣影评、去停用词、词云图、评论关键词绘图处理

    爬取豆瓣电影<大侦探皮卡丘>的影评,并做词云图和关键词绘图第一步:找到评论的网页url.https://movie.douban.com/subject/26835471/comments ...