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. docker运行dubbo-admin

    一:简介 dubbo-admin是dubbo框架的管理平台. 二: 创建继续镜像 Dockerfile FROM fangjipu/jdk8:8 RUN yum -y install epel-rel ...

  2. HDU 1069 Monkey and Banana(DP——最大递减子序列)

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 题意描述: 给n块砖,给出其长,宽和高 问将这n块砖,怎样叠放使得满足以下条件使得 ...

  3. 有用的linux命令笔记

    date cal [month] [year] bc 计算器 mkdir -p /home/bird/ 连续建立文件夹 mkdir -m 711 test2 创建文件夹是的权限 mv -i 询问是非覆 ...

  4. Node.js系列-http

    前言: 最近一直忙着公司项目的事,战友们的留言也没空回复,博客也有段时间没有更新了,年底了就是一个的忙啊~~~(ps:同感的也给个赞吧) 现在前端的就是一直地更新一直有新的东西出来,什么ES2015, ...

  5. The most interesting feature of iPhone X - FaceID

    No doubt everybody knows that iPhone 8 & iPhone X appear on the market. A feature called FaceID ...

  6. Centos系统下Lamp环境的快速搭建(超详细)

    lamp的搭建对于初学者是一件很头疼的事情,所以借此机会把自己当初快速搭建linux+apche+mysql+php的方法分享大家希望能到你. 工具/原料 虚拟机及Centos操作系统 Linux基本 ...

  7. 如何看apache的版本号

    在服务器上输入httpd -v就可以看到 在服务器上运行apachectl -v命令即可 Server version: Apache/2.2.3 Server built: Feb 25 2012 ...

  8. Mezzanine (Windows10下)安装配置与修改(更新中)

    最近自己搭个系统,发现Mezzanine很快,先搞个python 2.7, pip. 然后两个方法: 1. $ pip install mezzanine 2. Git下载,解压 后进入目录,创建项目 ...

  9. Struts 2 标签库及使用

    1  Struts 2 基本的标签属性. 1) name:指定表单元素的名称,该属性与Action中定义的属性相对应. 2) value:指定表单元素的值. 3) required:指定表单元素的必填 ...

  10. volatile特性及内存语义

    1.volatile变量自身具有下列特性:·可见性:对一个volatile变量的读,总是能看到(任意线程)对这个volatile变量最后的写入.·原子性:对任意单个volatile变量的读/写具有原子 ...