Codeforces Beta Round #52 (Div. 2)
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)的更多相关文章
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
随机推荐
- PHP中的 抽象类(abstract class)和 接口(interface)
抽象类abstract class 1 .抽象类是指在 class 前加了 abstract 关键字且存在抽象方法(在类方法 function 关键字前加了 abstract 关键字)的类. 2 .抽 ...
- delphi query阻塞执行 长时间执行sql的解决办法
delphi query 执行sql一直是阻塞执行,执行长时间的sql语句,程序没响应了,这时候只能用线程技术解决. 如今FDQuery有了CmdExecMode属性,可以设置amCancelDial ...
- day08-字符串操作
name = 'hello,world,WORLD! 123,你好' #capitalize()#首字母大写,其他全部变成小写,没有iscapitalize()方法print(name.capital ...
- Tomcat命令
如果原始内存不够用经常内存溢出,可以在catalina.bat中设置: 电脑2G内存的情况 :set JAVA_OPTS='-server -Xms1024m -Xmx1536m -XX:PermSi ...
- JSONArray
action层 js alert(result); result返回的是[{"countryId":"","id":"1&qu ...
- Druid参考配置
pom中的maven dependency <dependency> <groupId>com.alibaba</groupId> ...
- MOBA项目定点数的一个想法
能不能这样: 写逻辑时全用整数,不用每用到一个浮点数就要转一下成浮点数. 主要是除法 题细节较多,待思考
- oc字符串与c字符串转换和拷贝
// Helper method to create C string copy NSString* MakeNSString (const char* string) { if (string) { ...
- Haskell语言学习笔记(85)Async
安装 async $ cabal install async async-2.2.1 installed async / wait / concurrently async :: IO a -> ...
- [PHP]PHP的session机制,配置与高级应用
---------------------------------------------------------------------------------------------------- ...