拿下 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. 学通javaweb 24堂课 学习笔记

    17.01:简单配置控制器 1.一个controller protected ModelAndView handleRequestInternal(HttpServletRequest request ...

  2. opencv中的基本拼接

    普通版的图像拼接,事实上非常简单并且效果不很差. 实现方式: 新建工程: 去opencv里面[f:\opencv249\opencv\sources\samples\cpp]把stitching.cp ...

  3. 使用angular的ng-repeat遇到的一个问题

    问题描述:ng-repeat绑定的数据集动态更新之后其包裹的子元素所绑定的事件全部丢失:问题详述:问题代码如下: <style> img{width:100px;height:100px; ...

  4. 【转】为 XmlNode.SelectNodes 加上排序功能

    测试资料: <Config> <Item a='/> <Item a='/> <Item a='/> <Item a='/> <Ite ...

  5. [转]分布式系统为什么需要 Tracing?

    分布式系统为什么需要 Tracing?   先介绍一个概念:分布式跟踪,或分布式追踪.   电商平台由数以百计的分布式服务构成,每一个请求路由过来后,会经过多个业务系统并留下足迹,并产生对各种Cach ...

  6. 浏览器是如何运行HTML的?

     什么是网页  网页(HTML page)是在浏览器(Browser)上运行并且可以与用户产生互动的应用程序.                            此图为浏览器运行HTML 这个想说 ...

  7. c# xml 解析取值

    //字符串 string result = "<?xml version=\"1.0\" encoding=\"utf-8\"?>< ...

  8. 在Ubuntu Linux下安装Code::Blocks和Eclipse CDT

           最近小白由于有工作学习的需要,要尝试在Linux下进行C++编程.所以特地花了一点时间研究一下Linux下的C++的IDE.最后我尝试了使用Code::Blocks和Eclipse两个著 ...

  9. sql 理解视图

    可以看作是定义在sqlserver上的虚拟的表,本身并不存储数据,仅仅存储一个select语句和涉及的表的引用 通过视图,客户端不再需要知道底层表结构和其之间的关系,视图提供了一个统一访问数据的接口 ...

  10. T-SQL切割字符串方法小结

    T-SQL切割字符串方法小结,只有表值函数那个是自己的思想,其它都是来源于网络的思想,请大家不要笑话,嘻嘻~网上大牛太多,这点东西虽然上不了台面,但是也算是自己的一个学习吧,能够对一个人有用也行.再不 ...