Codeforces Beta Round #52 (Div. 2)
http://codeforces.com/contest/56
A
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 14 int n; 15 16 int main(){ 17 #ifndef ONLINE_JUDGE 18 freopen("input.txt","r",stdin); 19 #endif 20 std::ios::sync_with_stdio(false); 21 cin>>n; 22 map<string,int>mp; 23 mp["ABSINTH"]++; 24 mp["BEER"]++; 25 mp["BRANDY"]++; 26 mp["CHAMPAGNE"]++; 27 mp["GIN"]++; 28 mp["RUM"]++; 29 mp["SAKE"]++; 30 mp["TEQUILA"]++; 31 mp["VODKA"]++; 32 mp["WHISKEY"]++; 33 mp["WINE"]++; 34 string str; 35 int ans=0; 36 for(int i=1;i<=n;i++){ 37 cin>>str; 38 int tmp=0; 39 if(str[0]>='0'&&str[0]<='9'){ 40 for(int j=0;j<str.length();j++){ 41 tmp=tmp*10+str[j]-'0'; 42 } 43 if(tmp<18) ans++; 44 } 45 else{ 46 if(mp[str]) ans++; 47 } 48 } 49 cout<<ans<<endl; 50 }
B
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 14 int n; 15 int a[1005]; 16 int book[1005]; 17 18 int main(){ 19 #ifndef ONLINE_JUDGE 20 // freopen("input.txt","r",stdin); 21 #endif 22 std::ios::sync_with_stdio(false); 23 cin>>n; 24 int L=0,R=0; 25 int co=0; 26 int cc=0; 27 for(int i=1;i<=n;i++) { 28 cin>>a[i]; 29 if(a[i]!=i){ 30 book[i]=1; 31 if(L!=0) R=i; 32 if(L==0) L=i; 33 } 34 } 35 int pre=0x3f3f3f3f; 36 int flag=0; 37 for(int i=1;i<=n;i++){ 38 if(book[i]){ 39 if(pre<a[i]){ 40 flag=1; 41 } 42 pre=a[i]; 43 } 44 } 45 if(flag) cout<<"0 0"<<endl; 46 else{ 47 cout<<L<<" "<<R<<endl; 48 } 49 }
C
模拟
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 char S; 13 int n,ans; 14 string s[600]; 15 16 int main(){ 17 #ifndef ONLINE_JUDGE 18 freopen("input.txt","r",stdin); 19 #endif 20 std::ios::sync_with_stdio(false); 21 while(cin>>S) 22 { 23 if(S=='.') 24 { 25 for(int i=0;i<n;i++) 26 if(s[i]==s[n]) 27 ans++; 28 s[n]=""; 29 n--; 30 } 31 else 32 if(S==':' || S==',') 33 n++; 34 else 35 s[n]+=S; 36 } 37 cout<<ans<<endl; 38 }
D
DP +路径搜索,基础DP, 类似一道名为编辑距离的题目
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 string s1,s2; 14 int dp[1005][1005]; 15 16 void dfs(int i,int j){ 17 if(i==0&&j==0) return; 18 if(i&&dp[i-1][j]+1==dp[i][j]){ 19 dfs(i-1,j); 20 cout<<"DELETE"<<" "<<j+1<<endl; 21 } 22 else if(j&&dp[i][j-1]+1==dp[i][j]){ 23 dfs(i,j-1); 24 cout<<"INSERT"<<" "<<j<<" "<<s2[j-1]<<endl; 25 } 26 else{ 27 dfs(i-1,j-1); 28 if(s1[i-1]!=s2[j-1]) 29 cout<<"REPLACE"<<" "<<j<<" "<<s2[j-1]<<endl; 30 } 31 } 32 33 int main(){ 34 #ifndef ONLINE_JUDGE 35 freopen("input.txt","r",stdin); 36 #endif 37 std::ios::sync_with_stdio(false); 38 cin>>s1>>s2; 39 int len1=s1.length(); 40 int len2=s2.length(); 41 rep(i,1,len1+1) dp[i][0]=i; 42 rep(i,1,len2+1) dp[0][i]=i; 43 dp[0][0]=0; 44 rep(i,1,len1+1){ 45 rep(j,1,len2+1){ 46 dp[i][j]=min(min(dp[i-1][j],dp[i][j-1])+1,dp[i-1][j-1]+(s1[i-1]!=s2[j-1])); 47 } 48 } 49 cout<<dp[len1][len2]<<endl; 50 dfs(len1,len2); 51 }
E
DP 从后往前推,找出符合的距离 。想到逆向思路就很简单了
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1000005 9 #define rep(k,i,j) for(int k=i;k<j;k++) 10 typedef long long ll; 11 typedef unsigned long long ull; 12 13 int n; 14 struct sair{ 15 int x,h,pos,num; 16 }a[100005]; 17 18 bool cmp(sair a,sair b){ 19 return a.x<b.x; 20 } 21 22 bool cmp1(sair a,sair b){ 23 return a.pos<b.pos; 24 } 25 26 int main(){ 27 #ifndef ONLINE_JUDGE 28 freopen("input.txt","r",stdin); 29 #endif 30 std::ios::sync_with_stdio(false); 31 cin>>n; 32 for(int i=1;i<=n;i++){ 33 cin>>a[i].x>>a[i].h; 34 a[i].pos=i; 35 a[i].num=1; 36 } 37 sort(a+1,a+n+1,cmp); 38 for(int i=n-1;i>=1;i--){ 39 int j=i+1; 40 while(j<=n&&a[i].x+a[i].h>a[j].x){ 41 a[i].num+=a[j].num; 42 j=a[j].num+j; 43 } 44 } 45 sort(a+1,a+n+1,cmp1); 46 for(int i=1;i<=n;i++){ 47 cout<<a[i].num<<" "; 48 } 49 50 }