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语言中%d,%p,%u,%lu等都有什么用处

    %d 有符号10进制整数(%ld 长整型,%hd短整型 )%hu 无符号短整形(%u无符号整形,%lu无符号长整形)%i 有符号10进制整数 (%i 和%d 没有区别,%i 是老式写法,都是整型格式) ...

  2. [国嵌笔记][030][U-Boot工作流程分析]

    uboot工作流程分析 程序入口 1.打开顶层目录的Makefile,找到目标smdk2440_config的命令中的第三项(smdk2440) 2.进入目录board/samsung/smdk244 ...

  3. javascript 指定绑定函数名称,并且传递参数

      <html> <head> <title> New Document </title> <script type="text/jav ...

  4. .28-浅析webpack源码之compiler.resolvers

    原本该在过WebpackOptionsApply时讲解这个方法的,但是当时一不小心过掉了,所以在这里补上. compiler.resolvers 该对象的三个方法均在WebpackOptionsApp ...

  5. 快速搭建appium自动测试环境

    首先申明本文是基本于Python与Android来快速搭建Appium自动化测试环境: 主要分为以下几个步骤: 前提条件: 1)安装与配置python环境,打开 Python官网,找到"Do ...

  6. sql 中文转拼音首字母

    http://blog.csdn.net/zhanglong_longlong/article/details/46772571 --可支持大字符集20000个汉字! create function ...

  7. vue.js打包后,接口安全问题

    后面有一位朋友回答后台origin判断,但另一个朋友说可以通过代理请求就绕过跨域. 想想也对,代理的话origin就无效了,页面还是可以跑起来. 不知道有没有人想过这个问题,还是我想的方向有误,请各位 ...

  8. NSDateFormatter相关整理

    //实例化一个NSDateFormatter对象NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; //设定时间格式,这里可 ...

  9. SDP(3):ScalikeJDBC- JDBC-Engine:Fetching

    ScalikeJDBC在覆盖JDBC基本功能上是比较完整的,而且实现这些功能的方式比较简洁,运算效率方面自然会稍高一筹了.理论上用ScalikeJDBC作为一种JDBC-Engine还是比较理想的:让 ...

  10. python_将多个小字符拼接成大字符?

    案例: 下面有一个列表,如何把这个列表拼接成一个字符串? l = [1, 2, 3, 4, 'a', 'b', 'c'] 有哪些方法? 方法1: for进行迭代拼接 #!/usr/bin/python ...