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. 将简单的lambda表达式树转为对应的sqlwhere条件

    1.Lambda的介绍 园中已经有很多关于lambda的介绍了.简单来讲就是vs编译器给我带来的语法糖,本质来讲还是匿名函数.在开发中,lambda给我们带来了很多的简便.关于lambda的演变过程可 ...

  2. 浅析const、let与var

    以前无论声明变量还是常量,总是使用var一勺端,知道接触了es6之后,发现原来变量.常量的声明其实是很讲究的. 这里简单来谈谈var.const与let. 1.var.var声明的变量没有块级作用域, ...

  3. 基于逆波兰式的JAVA计算器

    请看下方↓↓  

  4. 本地phpstudy时常停机连接失败,php.ini文件中9000端口问题

    2018/01/05 13:35:07 [error] 20508#19380: *1 WSARecv() failed (10054: An existing connection was forc ...

  5. dedecms中{dede:myad name='about'/} 修改内容

    网站首页index.htm中调用这个命令,显示一段文字,但是想要修改内容.所以想知道这个命令指定的文件内容在哪里寻找或者指定内容在哪里修改? 匿名 | 浏览 6036 次 发布于2014-02-19 ...

  6. maven配置文件详解

    settings.xml 本篇文章主要对maven中setting.xml配置文件进行解释 1.声明规范 <settings xmlns="http://maven.apache.or ...

  7. 2017-07-02(free uptime cat /proc/cpuinfo uname lsb_release)

    free -b 字节为单位显示 -k KB为单位显示,默认显示就是KB -m 以MB为单位显示 -g 以GB为单位显示 free -m free 显示说明 uptime 跟top命令第一行内容相同 c ...

  8. JavaScript 教程:对象

    JavaScript 对象是拥有属性和方法的数据.学过编程语言的都知道,此处不再详述! 1.对象的定义: <script> </script> 对象也可以先创建,再添加属性和属 ...

  9. 【转】CentOS 6.3(x86_32)下安装Oracle 10g R2

    一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...

  10. ASP.NET Core Web APi获取原始请求内容

    前言 我们讲过ASP.NET Core Web APi路由绑定,本节我们来讲讲如何获取客户端请求过来的内容. ASP.NET Core Web APi捕获Request.Body内容 [HttpPos ...