拿下 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. C# 之 获取文件名及拓展名

    1.用Path类的方法(最常用) string fullPath = @"\WebSite\Default.aspx"; string filename = System.IO.P ...

  2. Oracle取得中文拼音首字母函数

    CREATE ) ; V_RETURN ) ; FUNCTION F_NLSSORT (P_WORD IN VARCHAR2) RETURN VARCHAR2 AS BEGIN RETURN NLSS ...

  3. JAVA_Gson_example

    package cn.kjxy.GSON; import java.util.List; import cn.kjxy.JSON.HttpHelpers; import com.google.gson ...

  4. C++第四章循环

    学习时候的点: 1.用户来控制是否继续进行的模板: char goonLoop=’y’; while(goonLoop==’y’){ //logic cout<<”输入y 来继续当前逻辑, ...

  5. JMS简介

    任何一个系统从整体上来看,其实质就是由无数个小的服务或事件(我们可以称之为事务单元)有机地组合起来的.对于系统中任何一个比较复杂的功能,都是通过调用各个独立的事务单元以实现统一的协调运作而实现的.现在 ...

  6. js 简易判断一个数字是否是小数

    参考:js验证输入是否是小数 我的方法是: //check the number is decimal number function checkDecimal(number){ if(!isNaN( ...

  7. for循环里面的判断条件

    先看下面这段代码,你很容易猜到结果 for(i=0;i<10;i++){ console.log(i); // 结果是打印出 1,2,3,4,5,6,7,8,9 } 再看一下这款代码,也许很容易 ...

  8. SqLite 框架 GreenDAO

    GreenDAO: 会生成一个数据访问,不用我们书写访问数据库的代码: 核心原理图 生成代码 就是用生成器生成一个对应的java类的生成工厂 public static void main(Strin ...

  9. android事件分发介绍

        Android事件分发 事件分发3个步骤 dispatchTouchEvent(event)派发 onInterceptTouchEvent(event)拦截 onTouchEvent(eve ...

  10. 再探Linux动态链接 -- 关于动态库的基础知识

      在近一段时间里,由于多次参与相关专业软件Linux运行环境建设,深感有必要将这些知识理一理,供往后参考. 编译时和运行时 纵观程序编译整个过程,细分可分为编译(Compiling,指的是语言到平台 ...