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. int n;
  14.  
  15. int main(){
  16. #ifndef ONLINE_JUDGE
  17. freopen("input.txt","r",stdin);
  18. #endif
  19. std::ios::sync_with_stdio(false);
  20. cin>>n;
  21. map<string,int>mp;
  22. mp["ABSINTH"]++;
  23. mp["BEER"]++;
  24. mp["BRANDY"]++;
  25. mp["CHAMPAGNE"]++;
  26. mp["GIN"]++;
  27. mp["RUM"]++;
  28. mp["SAKE"]++;
  29. mp["TEQUILA"]++;
  30. mp["VODKA"]++;
  31. mp["WHISKEY"]++;
  32. mp["WINE"]++;
  33. string str;
  34. int ans=;
  35. for(int i=;i<=n;i++){
  36. cin>>str;
  37. int tmp=;
  38. if(str[]>=''&&str[]<=''){
  39. for(int j=;j<str.length();j++){
  40. tmp=tmp*+str[j]-'';
  41. }
  42. if(tmp<) ans++;
  43. }
  44. else{
  45. if(mp[str]) ans++;
  46. }
  47. }
  48. cout<<ans<<endl;
  49. }

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. int n;
  14. int a[];
  15. int book[];
  16.  
  17. int main(){
  18. #ifndef ONLINE_JUDGE
  19. // freopen("input.txt","r",stdin);
  20. #endif
  21. std::ios::sync_with_stdio(false);
  22. cin>>n;
  23. int L=,R=;
  24. int co=;
  25. int cc=;
  26. for(int i=;i<=n;i++) {
  27. cin>>a[i];
  28. if(a[i]!=i){
  29. book[i]=;
  30. if(L!=) R=i;
  31. if(L==) L=i;
  32. }
  33. }
  34. int pre=0x3f3f3f3f;
  35. int flag=;
  36. for(int i=;i<=n;i++){
  37. if(book[i]){
  38. if(pre<a[i]){
  39. flag=;
  40. }
  41. pre=a[i];
  42. }
  43. }
  44. if(flag) cout<<"0 0"<<endl;
  45. else{
  46. cout<<L<<" "<<R<<endl;
  47. }
  48. }

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[];
  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=;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[][];
  15.  
  16. void dfs(int i,int j){
  17. if(i==&&j==) return;
  18. if(i&&dp[i-][j]+==dp[i][j]){
  19. dfs(i-,j);
  20. cout<<"DELETE"<<" "<<j+<<endl;
  21. }
  22. else if(j&&dp[i][j-]+==dp[i][j]){
  23. dfs(i,j-);
  24. cout<<"INSERT"<<" "<<j<<" "<<s2[j-]<<endl;
  25. }
  26. else{
  27. dfs(i-,j-);
  28. if(s1[i-]!=s2[j-])
  29. cout<<"REPLACE"<<" "<<j<<" "<<s2[j-]<<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,,len1+) dp[i][]=i;
  42. rep(i,,len2+) dp[][i]=i;
  43. dp[][]=;
  44. rep(i,,len1+){
  45. rep(j,,len2+){
  46. dp[i][j]=min(min(dp[i-][j],dp[i][j-])+,dp[i-][j-]+(s1[i-]!=s2[j-]));
  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[];
  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=;i<=n;i++){
  33. cin>>a[i].x>>a[i].h;
  34. a[i].pos=i;
  35. a[i].num=;
  36. }
  37. sort(a+,a+n+,cmp);
  38. for(int i=n-;i>=;i--){
  39. int j=i+;
  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+,a+n+,cmp1);
  46. for(int i=;i<=n;i++){
  47. cout<<a[i].num<<" ";
  48. }
  49.  
  50. }

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. TP的di

    依赖注入的意思是通过反射分析类所依赖的其他类,从容器中获取相应的对象并自动注入到类里面 首先依赖注入和控制反转说的是同一个东西,是一种设计模式,这种设计模式用来减少程序间的耦合,鄙人学习了一下,看TP ...

  2. C++中多态中构造函数与析构函数的调用

    做个实验,看一下成员变量的构造析构,父类子类的构造析构,以及虚函数对调用的影响. #include <iostream> using namespace std; class Member ...

  3. call 和 apply

    call和apply作用一样,都是为了转移this,区别在于传入参数的方式不同. this指当前方法所在的对象,如果方法的外面没有对象,则默认是window.由于闭包虽在调用的方法中,但是在创建的时候 ...

  4. APP-8-文本语音

    1.百度语音合成JS文件 baidu_tts_cors.js /** * 浏览器调用语音合成接口 * @param {Object} param 百度语音合成接口参数 * 请参考 https://ai ...

  5. pgsql restart

    /etc/init.d/postgresql restart

  6. 微信、陌陌等著名IM软件设计架构详解(转)

    对微信.陌陌等进行了分析,发出来分享一下(时间有些久了) 电量:对于移动设备最大的瓶颈就是电量了.因为用户不可能随时携带电源,充电宝.所以必须考虑到电量问题.那就要检查我们工程是不是有后台运行,心跳包 ...

  7. linux 2.6.32.220的一个crash记录

    有同事分析一个crash,我参与了分析,记录如下,供遇到相同crash的兄弟参考: crash> bt PID: TASK: ffff881723ce8080 CPU: COMMAND: &qu ...

  8. Java设置运行时环境参数

    一.代码中,如下: System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", " ...

  9. python实现根据指定字符截取对应的行的内容

    工作中遇到的,在一个.c文件中有很多函数,这个.c是自动生成的,需要将所有的函数通过extern放到.h中,每个函数都是UINT32 O_开头,通过正则表达式进行字符匹配以及通过linecache来截 ...

  10. 17.struts-开发流程.md

    目录 struts2.3.4 基本步骤 1. 导包,struts2.3有八个包要导入 2. 配置web.xml,引入struts核心功能,配置过滤器 3. 开发action 4. 配置action s ...