Codeforces Round #402 (Div. 2)


A.

日常沙比提

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,a[],b[],ans;
int main(){
//freopen("in","r",stdin);
n=read();
for(int i=;i<=n;i++) a[read()]++;
for(int i=;i<=n;i++) b[read()]++;
for(int i=;i<=;i++){
int c=a[i]+b[i];
if(c&) {puts("-1");return ;}
else ans+=abs(c/-a[i]);
}
printf("%d",ans/);
}

B.

日常沙比提2

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
char s[];
int n,k;
int main(){
//freopen("in","r",stdin);
scanf("%s",s+);k=read();
n=strlen(s+);
int c=;
for(int i=;i<=n;i++) if(s[i]=='') c++;
if(c<k) printf("%d",n-);
else{
int now=,zero=;
for(int i=n;i>=;i--){
if(s[i]=='') zero++;
else now++;
if(zero==k) break;
}
printf("%d",now);
}
}

C.

我去怎么这次三道沙比提

样例3良心!注意第一次买可以比$k$个多

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=2e5+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,k,ans;
struct Item{
int a,b,c;
bool operator <(const Item &r)const{
return c>r.c;
}
}a[N];
int main(){
//freopen("in","r",stdin);
n=read();k=read();
for(int i=;i<=n;i++) a[i].a=read();
for(int i=;i<=n;i++) a[i].b=read();
for(int i=;i<=n;i++) a[i].c=a[i].b-a[i].a;
sort(a+,a++n);
int i;
for(i=;i<=k;i++) ans+=a[i].a;
while(i<=n&&a[i].c>=) ans+=a[i].a,i++;
for(;i<=n;i++) ans+=a[i].b;
printf("%d",ans);
}

D.

题意:给两个字符串以及一个删除第一个字符串字符的操作序列,问多少次操作之后是最后的可以从第一个中找出第二个字符串的时刻

乱想一通,突然发现二分答案不就好了....

倒着处理变成加字符,二分加的字符的最晚时间最早,然后判定

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=2e5+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,t[N],m;
char a[N],b[N];
bool check(int g){
int now=;
for(int i=;i<=n;i++) if(t[i]<=g){
if(a[i]==b[now]) now++;
if(now>m) return true;
}
return false;
}
void solve(){
int l=,r=n,ans=;
while(l<=r){
int mid=(l+r)>>;
if(check(mid)) ans=mid,r=mid-;
else l=mid+;
}
printf("%d",n-ans);
}
int main(){
//freopen("in","r",stdin);
scanf("%s%s",a+,b+);
n=strlen(a+);
m=strlen(b+);
for(int i=;i<=n;i++) t[read()]=n-i+;
solve();
}

E.

写了40min然后放弃了好难写

Codeforces Round #402 (Div. 2)的更多相关文章

  1. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  2. Codeforces Round #402 (Div. 2) A,B,C,D,E

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  3. Codeforces Round #402 (Div. 2) D. String Game

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  4. Codeforces Round #402 (Div. 2) A B C sort D二分 (水)

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding

    暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...

  6. Codeforces Round #402 (Div. 2) 题解

    Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...

  7. Codeforces Round #402 (Div. 2) 阵亡记

    好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...

  8. CodeForces Round #402 (Div.2) A-E

    2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...

  9. Codeforces Round #402 (Div. 2) B

    Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...

随机推荐

  1. c++(单词统计)

    在面试环节中,有一道题目也是考官们中意的一道题目:如果统计一段由字符和和空格组成的字符串中有多少个单词? 其实,之所以问这个题目,考官的目的就是想了解一下你对状态机了解多少. (1) 题目分析 从题目 ...

  2. c++(查找)

    无论是数据库,还是普通的ERP系统,查找功能数据处理的一个基本功能.数据查找并不复杂,但是如何实现数据又快又好地查找呢?前人在实践中积累的一些方法,值得我们好好学些一下.我们假定查找的数据唯一存在,数 ...

  3. Hadoop2.7.5+Hbase1.4.0完全分布式

    Hadoop2.7.5+Hbase1.4.0完全分布式一.在介绍完全分布式之前先给初学者推荐两本书:<Hbase权威指南>偏理论<Hbase实战>实战多一些 二.在安装完全分布 ...

  4. Result Maps collection does not contain value for com.man.impet.dao.OrderBeanMapper.map

    由于mapper.xml中resultMap = "map"  改为 resultType="map"即可,折腾了一下午

  5. 从零开始学习前端JAVASCRIPT — 3、JavaScript基础string字符串介绍

    1:字符串 JS中的任何数据类型都可以当作对象来看.所以string既是基本数据类型,又是对象. 2:声明字符串 基本数据类型:var sStr = '字符串'; 对象的方法:var oStr = n ...

  6. dede list列表页和文章页分别使用if else

    标签: dede 2015-01-25 19:33 755人阅读 评论(0) 收藏 举报 分类: [ Dede ](20) 版权声明:本文为博主原创文章,未经博主允许不得转载. list列表页中使用i ...

  7. {style}/index_article.htm {style}表示什么意思啊

    LS有点安全意识好不好.... 在你的后台系统设置有个"模板默认风格:________  cfg_df_style " 默认是default也就是 {style}=模板路径+模板默 ...

  8. file_get_contents("php://input")的使用方法

    $data = file_get_contents("php://input"); //input 是个可以访问请求的原始数据的只读流. POST 请求的情况下,最好使用 php: ...

  9. vue2.0项目中使用Ueditor富文本编辑器示例

    最近在vue项目中需要使用富文本编辑器,于是将Ueditor集成进来,作为公共组件. 在线预览:https://suweiteng.github.io/vue2-management-platform ...

  10. Vuthink正确安装过程

    1.      下载项目vuethink,本例将项目放置website文件下. 2.      后台搭建 本地建站–>以phpstudy为例 1)      新建站点域名 <Virtual ...