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. python内建函数isinstance基础用法

      语法:isinstance(object,type) 作用:来判断一个对象是否是一个已知的类型.  其第一个参数(object)为对象,第二个参数(type)为类型名(int...)或类型名的一个 ...

  2. 从XMLHttpRequest请求响应里getResponseHeader(header)报错:Refused to get unsafe header "**" 问题解决

    问题产生原因: 原因1:W3C的 xhr 标准中做了限制,规定客户端无法获取 response 中的 Set-Cookie.Set-Cookie2这2个字段,无论是同域还是跨域请求: 原因2:W3C ...

  3. css样式小记

    溢出文字展现为... .over-hidd { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }

  4. 两种方法上传本地文件到github

    https://www.jianshu.com/p/c70ca3a02087 自从使用github以来,一直都是在github网站在线上传文件到仓库中,但是有时因为网络或者电脑的原因上传失败.最重要的 ...

  5. 腾讯云服务器php+mysq+nginx配置出现的问题及解决方法(亲测)

    http://blog.csdn.net/hfdmv/article/details/50900043 删除文件命令 sudo rm -f /usr/share/nginx/html/home.php ...

  6. sublime 中HTML快捷键

  7. 邓_PHP面试2

    又开始搞php了,好多php知识忘记了,学习php的方法是看面试题 下面是我搜集的一份php的面试题目 1.用PHP打印出前一天的时间格式是2006-5-10 22:21:21(2分) echo da ...

  8. ADO.NET复习总结(5)--工具类SqlHelper 实现登录

    工具类SqlHelper 即:完成常用数据库操作的代码封装 一.基础知识1.每次进行操作时,不变的代码: (1)连接字符串:(2)往集合存值:(3)创建连接对象.命令对象:(4)打开连接:(5)执行命 ...

  9. 一分钟搭建Vue2.0+Webpack2.0多页面项目

    想要自己一步步搭建的比较麻烦,不是很推荐,最少也要使用vue-cli,在其基础上开始搭建,今天我的主题是一分钟搭建,那么常规方法肯定不能满足的, 而我用的方法也很简单,就是使用已经配置完成的demo模 ...

  10. .net core 1.0 中的asp.net identity 基本使用(二)

    一.重写(覆盖)身份验证数据类型 1.修改Models目录中的ApplicationUser.cs类文件,如下 namespace xxxx.Models { //将应用程序用户的属性添加到应用程序 ...