Codeforces Beta Round #52 (Div. 2)

http://codeforces.com/contest/56

A

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int n; int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
map<string,int>mp;
mp["ABSINTH"]++;
mp["BEER"]++;
mp["BRANDY"]++;
mp["CHAMPAGNE"]++;
mp["GIN"]++;
mp["RUM"]++;
mp["SAKE"]++;
mp["TEQUILA"]++;
mp["VODKA"]++;
mp["WHISKEY"]++;
mp["WINE"]++;
string str;
int ans=;
for(int i=;i<=n;i++){
cin>>str;
int tmp=;
if(str[]>=''&&str[]<=''){
for(int j=;j<str.length();j++){
tmp=tmp*+str[j]-'';
}
if(tmp<) ans++;
}
else{
if(mp[str]) ans++;
}
}
cout<<ans<<endl;
}

B

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int n;
int a[];
int book[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
int L=,R=;
int co=;
int cc=;
for(int i=;i<=n;i++) {
cin>>a[i];
if(a[i]!=i){
book[i]=;
if(L!=) R=i;
if(L==) L=i;
}
}
int pre=0x3f3f3f3f;
int flag=;
for(int i=;i<=n;i++){
if(book[i]){
if(pre<a[i]){
flag=;
}
pre=a[i];
}
}
if(flag) cout<<"0 0"<<endl;
else{
cout<<L<<" "<<R<<endl;
}
}

C

模拟

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull;
char S;
int n,ans;
string s[]; int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
while(cin>>S)
{
if(S=='.')
{
for(int i=;i<n;i++)
if(s[i]==s[n])
ans++;
s[n]="";
n--;
}
else
if(S==':' || S==',')
n++;
else
s[n]+=S;
}
cout<<ans<<endl;
}

D

DP +路径搜索,基础DP, 类似一道名为编辑距离的题目

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; string s1,s2;
int dp[][]; void dfs(int i,int j){
if(i==&&j==) return;
if(i&&dp[i-][j]+==dp[i][j]){
dfs(i-,j);
cout<<"DELETE"<<" "<<j+<<endl;
}
else if(j&&dp[i][j-]+==dp[i][j]){
dfs(i,j-);
cout<<"INSERT"<<" "<<j<<" "<<s2[j-]<<endl;
}
else{
dfs(i-,j-);
if(s1[i-]!=s2[j-])
cout<<"REPLACE"<<" "<<j<<" "<<s2[j-]<<endl;
}
} int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>s1>>s2;
int len1=s1.length();
int len2=s2.length();
rep(i,,len1+) dp[i][]=i;
rep(i,,len2+) dp[][i]=i;
dp[][]=;
rep(i,,len1+){
rep(j,,len2+){
dp[i][j]=min(min(dp[i-][j],dp[i][j-])+,dp[i-][j-]+(s1[i-]!=s2[j-]));
}
}
cout<<dp[len1][len2]<<endl;
dfs(len1,len2);
}

E

DP  从后往前推,找出符合的距离  。想到逆向思路就很简单了

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int n;
struct sair{
int x,h,pos,num;
}a[]; bool cmp(sair a,sair b){
return a.x<b.x;
} bool cmp1(sair a,sair b){
return a.pos<b.pos;
} int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i].x>>a[i].h;
a[i].pos=i;
a[i].num=;
}
sort(a+,a+n+,cmp);
for(int i=n-;i>=;i--){
int j=i+;
while(j<=n&&a[i].x+a[i].h>a[j].x){
a[i].num+=a[j].num;
j=a[j].num+j;
}
}
sort(a+,a+n+,cmp1);
for(int i=;i<=n;i++){
cout<<a[i].num<<" ";
} }

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

  1. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  2. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  3. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  4. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  5. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  7. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  8. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  9. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

随机推荐

  1. Aop 基础

    基础文献 https://blog.csdn.net/abcd898989/article/details/50809321 简单Demo配置 pom.xml <!-- AOP --> & ...

  2. 模板引擎Dot

    Dot.js 很轻,处理速度也快,作为将json数据赋值到html页面的最好帮手. html5新引入的<template></template>就不用原先的<script ...

  3. leetcode 题解 word search。递归可以更简洁。

    先写上我的代码: 我总是不知道何时把任务交给下一个递归.以致于,写出的代码很臃肿! 放上别人递归的简洁代码: bool exist(char** board, int m, int n, char* ...

  4. ACM__并查集

    并查集是树型的数据结构,处理不想交集合 主要解决查找和合并的问题 步骤: 初始化 把每个点所在的集合初始化为自身 复杂度为O(N) 查找 查找元素所在的集合,即根节点 合并 将两个元素所在的集合合并在 ...

  5. compose配置文件参数详解

    转自:https://www.cnblogs.com/jsonhc/p/7814138.html 本文介绍compose配置文件参数的使用,熟练编写compose文件 [root@docker lnm ...

  6. 基于官方镜像MySQL做自定义业务扩充镜像

    转自:https://www.cnblogs.com/jsonhc/p/7809571.html 首先从https://hub.docker.com/_/mysql/拉取官方镜像,如果速度缓慢,建议添 ...

  7. The Google File System 中文版

    摘要 我们设计并实现了Google文件系统,一个面向分布式数据密集型应用的.可伸缩的分布式文件系统.虽然运行在廉价的日用硬件设备上,但是它依然了提供容错功能,为大量客户机提供了很高的总体性能. 虽然与 ...

  8. Eclipse SVN文件冲突及不能直接提交情况

    下图为Eclipse SVN使用过程中存在文件冲突的情形. 以下是三种冲突情形及相应解决办法: 1.简单的文件版本冲突 情形:A改变了文件的头部,B改变了文件的尾部,如果两者改动互不影响,SVN可以智 ...

  9. webstorm添加多个项目

    在webstorm工作目录下,添加其他项目,不用每个项目打开一个webstorm,刚开始使用webstorm的时候,每次打开一个项目的时,都要打开一个开发界面,在这几个窗口之间来回的切换,有一天真的感 ...

  10. 二叉堆复习(包括d堆)

    要期中考了……我真的是什么也不会啊,书都没看过TAT. 好吧整理一下二叉堆,这里就以最大堆为例好了. 首先二叉堆其实是一棵CBT,满足父节点的键值大于左右子节点的键值(wikipedia把这个叫键值, ...