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. 使用cuteFTP与虚拟机交互文件---安装ftp服务

    安装ftp服务,以便在Windows中使用cuteFTP与虚拟机交互文件,使用sudo apt-get install vsftpd 安装完后,打开/etc/vsftpd.conf文件,去掉local ...

  2. day43-socketserver

    基于tcp的套接字,关键就是两个循环,一个链接循环,一个通信循环 socketserver模块中分两大类:server类(解决链接问题)和request类(解决通信问题) server类: reque ...

  3. math模块

    序号 方法 功能 示例 1 matd.ceil 取大于等于x的最小的整数值,如果x是一个整数,则返回x print(matd.ceil(10.1))# 11print(matd.ceil(-3.1)) ...

  4. mfc cef<转>

    在mfc单文档程序中加入cef: .在BOOL CtestCEFApp::InitInstance()中初始化cef HINSTANCE hInst = GetModuleHandle(NULL); ...

  5. Python基本数据类型以及字符串

    基本数据类型                数字  int ,所有的功能,都放在int里            a1 = 123            a1 = 456                 ...

  6. html 基础之a标签的属性target解析

    学习前端,有很多标签其实有很多不同的功能,但是用到的不多,所以就没有发现:当发现的时候,觉得很不可思议,有耳目一新的感觉.例如a 标签,之前只是知道,使用a标签,可以打开一个链接,然后访问一个新的页面 ...

  7. Grafana分析Nginx日志

    配置Groub by -Terms时报错,提示需要设置fielddata=true,报错内容大概如下: "Fielddata is disabled on text fields by de ...

  8. 处于ESTABLISHED 状态的socket 却没有进程信息

    接<一次docker中的nginx进程响应慢问题定位记录> 在排查这个问题的时候,我先使用netstat 去查看,看到底是内核协议栈的连接请求没给到进程,还是进程accept链路慢了,或者 ...

  9. 【转】解决Eclipse中SVN版本信息不显示的问题

    eclipse 中使用 svn 插件,原本正常,未作任何更改,最近几天突然eclipse 中查看文件时,文件后面的 版本号 . 文件的状态图标 等等都不见了.以为有插件冲突,卸载了好多其他的相关的插件 ...

  10. javascript 模拟java 实现继承的5种方式

    1.继承第一种方式:对象冒充 function Parent(username){ this.username = username; this.hello = function(){ alert(t ...