Codeforces Round #496 (Div. 3) ABCDE1
//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的更多相关文章
- 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 题意 ...
- Codeforces Round #496 (Div. 3)
一如既往地四题...好久没切了 有点犯困了明显脑子感觉不够灵活. 为了熟练度还是用java写的,,,导致观赏性很差...我好不容易拉了个队友一起切结果过掉a就tm挂机了!!! A题竟然卡了,,,用了十 ...
- 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 ...
- Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths
F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...
- Codeforces Round #496 (Div. 3) E2 - Median on Segments (General Case Edition)
E2 - Median on Segments (General Case Edition) 题目大意:给你一个数组,求以m为中位数的区间个数. 思路:很巧秒的转换,我们把<= m 数记为1, ...
- Codeforces Round #496 (Div. 3) E1. Median on Segments (Permutations Edition) (中位数,思维)
题意:给你一个数组,求有多少子数组的中位数等于\(m\).(若元素个数为偶数,取中间靠左的为中位数). 题解:由中位数的定义我们知道:若数组中\(<m\)的数有\(x\)个,\(>m\)的 ...
- Codeforces Round #496 (Div. 3) D. Polycarp and Div 3 (数论)
题意:给你一个巨长无比的数,你可以将这个数划成任意多个部分,求这些部分中最多有多少个能被\(3\)整除. 题解:首先我们遍历累加每个位置的数字,如果某一位数或者累加和能被\(3\)整除(基础知识,不会 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- Mavlink协议理解
来源:blog.csdn.net/super_mice/article/details/44836585 之前看了mavlink协议,网上关于mavlink的资料不多.本文大概总结了下对mavlink ...
- C++编写字符串类CNString,该类有默认构造函数、类的拷贝函数、类的析构函数及运算符重载
编码实现字符串类CNString,该类有默认构造函数.类的拷贝函数.类的析构函数及运算符重载,需实现以下“=”运算符.“+”运算.“[]”运算符.“<”运算符及“>”运算符及“==”运算符 ...
- COGS 11. 运输问题1
★★☆ 输入文件:maxflowa.in 输出文件:maxflowa.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 一个工厂每天生产若干商品,需运输到 ...
- linux 命令——21 find(转)
在 使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命 令长度有限制,这样在find命令运行几分钟之后,就 ...
- 关于ffmpeg(libav)解码视频最后丢帧的问题
其实最初不是为了解决这个问题而来的,是Peter兄给我的提示解决另一个问题却让我误打误撞解决了另外一个问题之后也把这个隐藏了很久的bug找到(之前总是有一些特别短的视频产生不知所措还以为是视频素材本身 ...
- hdu-3572 Task Schedule---最大流判断满流+dinic算法
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3572 题目大意: 给N个任务,M台机器.每个任务有最早才能开始做的时间S,deadline E,和持 ...
- 【HDU4507】恨7不成妻(数位DP)
点此看题面 大致题意: 让你求出一段区间内与\(7\)无关的数的平方和.与\(7\)无关的数指整数中任意一位不为\(7\).整数的每一位加起来的和不是\(7\)的整数倍.这个整数不是\(7\)的倍数. ...
- CSS3 - - Media(css3媒介查询) 属性
语法结构及用法: @media 设备名 only (选取条件) not (选取条件) and(设备选取条件),设备二{sRules} 实际应用一 判断设备横竖屏: /* 这是匹配横屏的状态,横屏时的 ...
- python_43_移动文件指针补充
#移动文件指针补充 ''' 文件对象.seek((offset,where)) offset:移动的偏移量,单位为字节.等于正数时向文件尾方向移动,等于负数时向文件头方向移动文件指针 where:指针 ...
- Ubuntu安装mysql和简单使用
一.安装mysql sudo apt-get install mysql-server sudo apt-get isntall mysql-client sudo apt-get install l ...