Google Practice Round China New Grad Test 2014

来源:互联网 发布:stc15w104编程 编辑:程序博客网 时间:2024/05/22 01:56

1)  CaptainHammer

Problem:

The Hamjet is a true marvel of aircraftengineering. It is a jet airplane with a single engine so powerful that itburns all of its fuel instantly during takeoff. The Hamjet doesn't have anywings because who needs them when the fuselage is made of a specialWonderflonium isotope that makes it impervious/抗渗的不透水的to harm.

Piloting the Hamjet is a not a job for yourtypical, meek-bodied superhero. That's why the Hamjet belongs to CaptainHammer, who is himself impervious to harm. The G-forces that the pilot endureswhen taking a trip in the Hamjet are legen-dary.

The Hamjet takes off at an angle of θdegrees up and a speed of V meters per second. Vis a fixed value that isdetermined by the awesome power of the Hamjet engine and the capacity of itsfuel tank. The destination is D meters away. Your job is to program theHamjet's computer to calculate θ given V and D.

Fortunately, the Hamjet's Wondeflonium hullis impervious to air friction. Even more fortunately, the Hamjet doesn't flytoo far or too high, so you can assume that the Earth is flat, and that theacceleration due to gravity is a constant 9.8 m/s2 down.

Input

The first line of the input gives the numberof test cases, T. T lines follow. Each line will contain two positive integers-- V and D.

Output

For each test case, output one linecontaining "Case #x: θ", where x is the case number (starting from 1)and θ is in degrees up from the the horizontal. If there are several possibleanswers, output the smallest positive one.

An answer will be considered correct if it is within 10-6 of the exact answer, in absoluteor relative error. See the FAQ for an explanation of what that means, and whatformats of floating-point numbers we accept.

Limits

1 ≤ T ≤ 4500;

1 ≤ V ≤ 300;

1 ≤ D ≤ 10000;

It is guaranteed that each test case will besolvable.

Sample:


Input

3

98 980

98 490

299 1234

Output

 

Case #1: 45.0000000

Case #2: 15.0000000

Case #3: 3.8870928


    此问题为一物理问题,求初始速度的夹角。可以将速度的分解,横向为匀速运动,速度为vcosθ,而竖直方向坐初速度为vsinθ,加速度为-g的先减速后加速运动,根据位移公式,当其由出发点抵达中间时,S=0=vsinθ*t-g*t^2/2;与匀速直线运动联立代入时间即可。

#include <iostream>  #include <fstream>  #include <string>  #include <vector>  #include <map>  #include <iomanip>  using namespace std;  #define EPS 1e-8  const double PI = acos(-1.0);      int main()   {      // open files      ifstream fin ("B-small-attempt2.in");      ofstream fout ("A-small_my.out");        if (!fin.good())          cout << "file is not prepared!" << endl;        // read the cases      int nCase; // number of cases      fin >> nCase;      for (int i = 1; i <= nCase; ++i)      {          int V, D;          fin >> V >> D;          double t = min (9.8 * D / (V * V * 1.0), 1.0);         double theta = 0.5 * asin(t) * 180 / PI;          fout << std::fixed << setprecision(7) << "Case #" << i << ": " << theta << endl;      }      // close files      fin.close();      fout.close();      return 0;  }  


2)  Changing Cards

Problem: Case:

Moist has a hobby -- collecting figureskating trading cards. His card collection has been growing, and it is now toolarge to keep in one disorganized pile. Moist needs to sort the cards inalphabetical order, so that he can find the cards that he wants on short noticewhenever it is necessary.

The problem is -- Moist can't actually pickup the cards because they keep sliding out his hands, and the sweat causespermanent damage. Some of the cards are rather expensive, mind you. Tofacilitate the sorting, Moist has convinced Dr. Horrible to build him a sortingrobot. However, in his rather horrible style, Dr. Horrible has decided to makethe sorting robot charge Moist a fee of $1 whenever it has to move a tradingcard during the sorting process.

Moist has figured out that the robot'ssorting mechanism is very primitive. It scans the deck of cards from top tobottom.Whenever it finds a card that islexicographically smaller than the previous card, it moves that card to itscorrect place in the stack above. This operation costs $1, and the robotresumes scanning down towards the bottom of the deck, moving cards one by oneuntil the entire deck is sorted in lexicographical order from top to bottom.

As wet luck would have it, Moist is almostbroke, but keeping his trading cards in order is the only remaining joy in hismiserable life. He needs to know how much it would cost him to use the robot tosort his deck of cards.

Input

The first line of the input gives the numberof test cases, T. T test cases follow. Each one starts with a line containing asingle integer, N. The next N lines each contain the name of a figure skater,in order from the top of the deck to the bottom.

Output

For each test case, output one linecontaining "Case #x: y", where x is the case number (starting from 1)and y is the number of dollars it would cost Moist to use the robot to sort hisdeck of trading cards.

Limits

1 ≤ T ≤ 100.

Each name will consist of only letters andthe space character.

Each name will contain at most 100characters.

No name with start or end with a space.

No name will appear more than once in thesame test case.

Lexicographically, the space character comesfirst, then come the upper case letters, then the lower case letters.

Small dataset

1 ≤ N ≤ 10.

Large dataset

1 ≤ N ≤ 100.

Sample:


Input

2

2

Oksana Baiul

Michelle Kwan

3

Elvis Stojko

Evgeni Plushenko

Kristi Yamaguchi

Output

Case #1: 1

Case #2: 0

 这是一个类似插入排序的排序方式,机器人从头开始找,当发现,比前一个小的卡片时将其插入到合适的位置,收费1元。所以我们只要找有多少大于当前最后一个值的结果即可。

void card_change(char *path)  {      fstream infile;      ofstream ofile;      infile.open(path);      if (!infile)      {          cout<<"file open wrong!"<<endl;          return;      }      ofile.open("output.out");      if (!infile.eof())      {          int test_num(0);          infile>>test_num;          int money;          for (int i=0;i<test_num;i++)          {              money=0;              int card_number(0);              infile>>card_number;              char **card_name;               card_name= new char *[card_number];               for(int j=0;j<card_number;++j)                   card_name[j] = new char[100];               infile.getline(card_name[0],100,'\n');              for (int j=0;j<card_number;j++)                  infile.getline(card_name[j],100,'\n');              char *maxstr=card_name[0];              for (int m=0;m<card_number-1;m++)              {                                 if (strcmp(card_name[m+1],maxstr)>0)                      maxstr=card_name[m+1];                  else                      money++;                }              ofile<<"Case #"<<i+1<<": "<<money<<endl;              for(int j=0;j<card_number;++j)                   delete [] card_name[j];              delete [] card_name;          }      }      cout<<"processed."<<endl;      return;  } 


3)  Non Coexist

Problem:

As the leader of the Evil League of Evil,Bad Horse has a lot of problems to deal with. Most recently, there have beenfar too many arguments and far too much backstabbing in the League, so much sothat Bad Horse has decided to split the league into two departments in order toseparate troublesome members. Being theThoroughbred of Sin, Bad Horse isn't about to spend his valuable time figuringout how to split the League members by himself. That what he's got you -- hisloyal henchman -- for.

Input

The first line of the input gives the numberof test cases, T. T test cases follow. Each test case startswith a positive integer M on a line by itself -- the number oftroublesome pairs of League members. The next M lines each contain apair of names, separated by a single space.

Output

For each test case, output one linecontaining "Case #x: y", where x is the case number (starting from 1)and y is either "Yes" or "No", depending on whether theLeague members mentioned in the input can be split into two groups with neitherof the groups containing a troublesome pair.

Limits

1 ≤ T ≤ 100.
Each member name will consist of only letters and the underscore character.Namesare case-sensitive.
No pair will appear more than once in the same test case.Each pair will containtwo distinct League members.

Small dataset

1 ≤ M ≤ 10.

Large dataset

1 ≤ M ≤ 100.

Sample



Input :

2
1
Dead_Bowie  Fake_Thomas_Jefferson
3
Dead_Bowie  Fake_Thomas_Jefferson
Fake_Thomas_Jefferson  Fury_Leika
Fury_Leika   Dead_Bowie


Output: 

Case #1: Yes
Case #2: No

 

此题的基本题意即为同一行内的两人不能位于同一组中,要求将所有这样的非共存组分开。编程思路如下,将各个人名通过map映射成为数字,便于查找与存储,而后将非共存线段存入EdgeSet中,对其进行染色,即如果0与1,2不能共存,则若0染为白色0则1,2必须染为黑色1,如果已经对其染色为0,则表示该组无法共存。返回即可。


#include <iostream>  #include <cstdio>  #include <string.h>  #include <map>  #include <vector>  #include <fstream>  #include <string>  using namespace std;    int t, m, tot;  string a, b;  map<string, int> mp;  vector< vector<int> > EdgeSet;  int color[201];//at most 200 pairs of names   bool dfs(int cur, int col) {      if (color[cur] != -1)       {// allocated          if (color[cur] == col)                return true;          else              return false;      }      bool flag = true;      color[cur] = col;      int nxt;      for (unsigned int i = 0; i < EdgeSet[cur].size(); i++)       {          nxt = EdgeSet[cur][i];          if (!dfs(nxt, 1 - col))              return false;      }      return true;  }    int bad_horse ()  {     freopen("t.txt", "r", stdin);      freopen("t1.txt", "w", stdout);      cin >> t;//case number      for (int z = 1; z <= t; z++) {          cin >> m;//name number          tot = 0;          mp.clear();          EdgeSet.clear();          EdgeSet.assign(200, vector<int>());          memset(color, -1, sizeof(color));          for (int i = 0; i < m; i++) {              cin >> a >> b;//two non-exist name              //assign string to a number              if (mp.find(a) == mp.end()) mp[a] = tot++;              if (mp.find(b) == mp.end()) mp[b] = tot++;              //memory the non-exist pairs              EdgeSet[ mp[a] ].push_back(mp[b]);              EdgeSet[ mp[b] ].push_back(mp[a]);          }          bool flag = true;          for (int i = 0; i < tot && flag; i++) {              if (color[i] == -1) {                  if (!dfs(i, 0))                     flag = false;              }          }          if (flag)   cout << "Case #" << z << ": Yes\n";          else          {              cout << "Case #" << z << ": No\n";          }      }       return 0;  }



原创粉丝点击