拿下 ABD, 顺利晋级, 预赛的时候C没有仔细想,推荐C题,一个非常不错的构造题目!

A Magic Trick 简单的题目来取得集合的交并

   1:  #include <iostream>
   2:  #include <algorithm>
   3:  #include <set>
   4:  #include <vector>
   5:  using namespace std;
   6:  int main()
   7:  {
   8:      freopen("A-small-attempt0.in","r",stdin);
   9:      freopen("A-small-attempt0.out","w",stdout);
  10:      int T;
  11:      cin>>T;
  12:      for(int t=1; t<=T; t++)
  13:      {
  14:          int x,y;
  15:          cin>>x;
  16:          int m[4][4];
  17:          set<int> X;
  18:          for(int i=0; i<4; i++)
  19:          {
  20:              for(int j=0; j<4; j++)
  21:              {
  22:                  cin>>m[i][j];
  23:                  if(i+1  == x) X.insert(m[i][j]);
  24:              }
  25:          }
  26:          cin>>y;
  27:          set<int> Y;
  28:          for(int i=0; i<4; i++)
  29:          {
  30:              for(int j=0; j<4; j++)
  31:              {
  32:                  cin>>m[i][j];
  33:                  if(i+1  == y) Y.insert(m[i][j]);
  34:              }
  35:          }
  36:          vector<int> ret(X.size() + Y.size());
  37:          auto itr = set_intersection(X.begin(),X.end(), Y.begin(),Y.end(), ret.begin());
  38:          ret.resize(itr - ret.begin());
  39:          cout<<"Case #"<<t<<": ";
  40:          if(ret.size() == 1)
  41:              cout<<ret[0]<<endl;
  42:          else if(ret.size() > 1)
  43:          {
  44:              cout<<"Bad magician!"<<endl;
  45:          } else  cout<<"Volunteer cheated!"<<endl;
  46:      }
  47:  }

B Cookie Clicker Alpha  核心观察可以通过简单的推导获得一个upper  bound,然后枚举到这个upper bound就OK。

   1:  #include <iostream>
   2:  #include <cmath>
   3:  using namespace std;
   4:   
   5:  int main()
   6:  {
   7:      freopen("B-large.in","r",stdin);
   8:      freopen("B-large.out","w",stdout);
   9:      int T;
  10:      cin>>T;
  11:      for(int t = 1; t<= T; t++)
  12:      {
  13:          double C,F,X;
  14:          cin>>C>>F>>X;
  15:   
  16:          double ret = X/2.0;
  17:          int up = max( (F*X - 2*C)/(F*C), 0.0);
  18:          //cout<<up<<endl;
  19:          double Nec = 0.0f;
  20:          for(int k = 0; k< up; k++)
  21:          {
  22:              Nec += C/(2+k*F);
  23:              ret = min(ret, Nec + X/(2+(k+1)*F));
  24:          }
  25:          printf("Case #%d: %.7f\n", t, ret);
  26:          //cout<<"Case #"<<t<<": "<<ret<<endl;
  27:      }
  28:  }

C Minesweeper Master  这是一个构造的题目,非常非常的不错!核心观察在于扫雷的机制在边界的时候需要是2*n的这样一个结构才可能保证顺利完成边界情况。

   1:  #include <iostream>
   2:   
   3:  using namespace std;
   4:   
   5:  char Map[55][55];
   6:  int main()
   7:  {
   8:      freopen("C-large-practice.in","r",stdin);
   9:      freopen("C-large-practice.out","w",stdout);
  10:      int T; cin>>T;
  11:   
  12:      for(int t= 1; t<=T; t++)
  13:      {
  14:          bool possible = false;
  15:          int R,C,M;
  16:          cin>>R>>C>>M;
  17:          for(int i=0; i<R; i++)
  18:          {
  19:              for(int j=0; j<C; j++)
  20:              {
  21:                  Map[i][j] = '*';
  22:              }
  23:          }
  24:          if(R == 1 || C == 1 || R*C == M+1)
  25:          {
  26:              possible = true;
  27:              Map[0][0] = 'c';
  28:              int num = R*C - M-1;
  29:              for(int i=0; i<R; i++)
  30:              {
  31:                  for(int j=0; j<C; j++)
  32:                  {
  33:                      if(i==0 && j==0) continue;
  34:                      else if(num >0)
  35:                      {
  36:                          Map[i][j] = '.';
  37:                          num--;
  38:                      }else Map[i][j] = '*';
  39:                  }
  40:              }
  41:          }else
  42:          {
  43:              for(int r = 2; r<=R; r++)
  44:              {
  45:                  for(int c = 2; c<=C; c++)
  46:                  {
  47:                      int mineleft = M - (R*C - r*c);
  48:                      if( mineleft <= (r-2)*(c-2) && mineleft >=0)
  49:                      {
  50:                          possible = true;
  51:                          for(int i=0; i<R; i++) for(int j=0; j<C; j++)Map[i][j] = '*';
  52:                          Map[0][0]= 'c';
  53:                          for(int i=0; i<2; i++) for(int j=0; j<c; j++)
  54:                          {
  55:                              if(i ==0 && j==0) continue;
  56:                              Map[i][j] = '.';
  57:                          }
  58:                          for(int i=2; i<r; i++) for(int j=0; j<2; j++) Map[i][j] = '.';
  59:                          mineleft = (r-2)*(c-2) - mineleft;
  60:                          for(int i= 2; i<r; i++) for(int j=2; j<c; j++)
  61:                          {
  62:                              if(mineleft > 0)
  63:                              {
  64:                                  mineleft --;
  65:                                  Map[i][j] = '.';
  66:                              } else Map[i][j] = '*';
  67:   
  68:                          }
  69:                      }
  70:   
  71:                  }
  72:              }
  73:   
  74:          }
  75:          cout<<"Case #"<<t<<":"<<endl;
  76:          if(possible)
  77:          {
  78:              for(int i=0; i<R; i++)
  79:              {
  80:                  for(int j=0; j<C; j++)
  81:                  {
  82:                      cout<<Map[i][j];
  83:                  }
  84:                  cout<<endl;
  85:              }
  86:          }
  87:          else
  88:          {
  89:              cout<<"Impossible"<<endl;
  90:          }
  91:      }
  92:  }

详细的分析参见:http://www.huangwenchao.com.cn/2014/04/gcj-2014-qual.html

D Deceitful War 类似于田忌赛马的问题,核心观察在于 每一个人的最优策略都是采用刚刚比你大的来进行比较。

   1:  #include <iostream>
   2:  #include <vector>
   3:  #include <algorithm>
   4:   
   5:  using namespace std;
   6:   
   7:  int main()
   8:  {
   9:      freopen("D-large.in","r",stdin);
  10:      freopen("D-large.out","w",stdout);
  11:      int T; cin>>T;
  12:      for(int t=1; t<= T; t++)
  13:      {
  14:          int N;
  15:          cin>>N;
  16:          vector<double> A(N);
  17:          vector<double> B(N);
  18:          for(int i=0; i<N; i++) cin>>A[i];
  19:          for(int i=0; i<N; i++) cin>>B[i];
  20:          sort(A.begin(), A.end());
  21:          sort(B.begin(), B.end());
  22:          int War = 0;
  23:          for(int i = A.size()-1, j= B.size()-1; i>=0 && j>= 0;)
  24:          {
  25:              if(B[j]>A[i])
  26:              {
  27:                  War++;
  28:                  i--;
  29:                  j--;
  30:              } else if(B[j] <A[i])
  31:              {
  32:                  i--;
  33:              }
  34:          }
  35:          //cout<<N - War<<endl;
  36:          int NOWar = 0;
  37:          for(int i = B.size()-1, j= A.size()-1; i>=0 && j>= 0;)
  38:          {
  39:              if(A[j]>B[i])
  40:              {
  41:                  NOWar++;
  42:                  i--;
  43:                  j--;
  44:              } else if(A[j] <B[i])
  45:              {
  46:                  i--;
  47:              }
  48:          }
  49:          //cout<<NOWar<<endl;
  50:          cout<<"Case #"<<t<<": "<<NOWar<<" "<<N-War<<endl;
  51:      }
  52:      return 0;
  53:  }

Google Code Jam 2014 Qualification 题解的更多相关文章

  1. Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha

    Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...

  2. Google Code Jam 2009 Qualification Round Problem C. Welcome to Code Jam

    本题的 Large dataset 本人尚未解决. https://code.google.com/codejam/contest/90101/dashboard#s=p2 Problem So yo ...

  3. Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle

    Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...

  4. Google Code Jam 2014 资格赛:Problem D. Deceitful War

    This problem is the hardest problem to understand in this round. If you are new to Code Jam, you sho ...

  5. Google Code Jam 2009 Qualification Round Problem B. Watersheds

    https://code.google.com/codejam/contest/90101/dashboard#s=p1 Problem Geologists sometimes divide an ...

  6. Google Code Jam 2009 Qualification Round Problem A. Alien Language

    https://code.google.com/codejam/contest/90101/dashboard#s=p0 Problem After years of study, scientist ...

  7. Google Code Jam 2014 Round 1 A:Problem A Charging Chaos

    Problem Shota the farmer has a problem. He has just moved into his newly built farmhouse, but it tur ...

  8. Google Code Jam 2014 Round 1B Problem B

    二进制数位DP,涉及到数字的按位与操作. 查看官方解题报告 #include <cstdio> #include <cstdlib> #include <cstring& ...

  9. Google Code Jam 2015 Round1A 题解

    快一年没有做题了, 今天跟了一下 GCJ Round 1A的题目, 感觉难度偏简单了, 很快搞定了第一题, 第二题二分稍微考了一下, 还剩下一个多小时, 没仔细想第三题, 以为 前两个题目差不多可以晋 ...

随机推荐

  1. STC89C52单片机内部EEPROM驱动

    STC89C52单片机自身带有4K的存储空间,分为8个扇区,每个扇区512字节,第一扇区起始地址为:0x2000, 结束地址为:21FF, 第八扇区起始地址为0x2E00,结束地址是2FFF #inc ...

  2. 马上搞定Android平台的Wi-Fi Direct开发

    导语 移动互联网时代,很多用户趋向于将大量的资料保存在移动设备上.但在给用户带来便利的同时引发了一个新的问题——保存在移动设备上的资料该怎样共享出去?到了思考时间,普通青年这样想:折腾什么劲啊,直接用 ...

  3. 【转载】Hadoop和大数据:60款顶级大数据开源工具

    一.Hadoop相关工具 1. Hadoop Apache的Hadoop项目已几乎与大数据划上了等号.它不断壮大起来,已成为一个完整的生态系统,众多开源工具面向高度扩展的分布式计算. 支持的操作系统: ...

  4. 让ubuntu开启ssh服务以及让vi/vim正常使用方向键与退格键

    VIM 修复方法: 安装vim full版本,在full版本下键盘正常,安装好后同样使用vi命令.ubuntu预装的是vim tiny版本,而需要的是vim full版本.执行下面的语句安装vim f ...

  5. [转]Oracle学习笔记——权限管理

    本文转自:http://www.cnblogs.com/whgw/archive/2011/10/30.html 一.系统的默认用户 1)sys用户是超级用户,具有最高权限,具有sysdba角色,有c ...

  6. 浅谈用java解析xml文档(一)

    关于xml本身的语法及使用的环境不多说了,网上有很多规则, 然对xml文档进行解析,一般分为四种解析方式,基于java官方文档的Dom 和Sax解析,还有就是基于 第三方jar包的 Jdom 和 Do ...

  7. MYSQL之性能优化 ----MySQL性能优化必备25条

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我 们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数 ...

  8. Better Completion插件使用

    最近学习Bootstrap,发现Sublime text2不支持Bootstrap的代码提示,所以得装一个Bootstrap的代码提示插件.试了好几个之后发现Better-Completion最方便, ...

  9. 【转】Error: no `server' JVM at `C:\Program Files\Java\jre6\bin\server\jvm.dll'.解决办法

    出现问题: 用java -jar XXX.jar -server -Xms900m -Xmx900m 或者 java -server -version 提示错误 Error: no `server' ...

  10. 启用Win8(中文版/核心版)中被阉割的远程桌面服务端

    Windows 8/8.1 标准版(中文版/核心版)中取消了远程桌面服务端,想通过远程连接到自己的电脑就很麻烦了,第三方远程桌面速度又不理想(如TeamViewer).通过以下方法可让系统恢复远程桌面 ...