Google笔试(2015年8月)
华电北风吹
天津大学认知计算与应用重点实验室
日期:2015/8/21
这三道题目的PDF能够在这里下载
https://github.com/ncepuzhengyi/jobHuntingExam/tree/master/jobExam/Problem_20150815_google
Problem 1:
问题1是眼下须要将阻止分成两块,因为组织内有些人之间有矛盾不能分到同一组内。问你是否存在这种划分。
问题一是二分图推断问题,仅仅须要推断无向图是否是二分图就可以。
最简单的方法是採用广度优先搜索+染色法就可以。
#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <deque>
using namespace std;
#define size 5
int graph[size][size];
int visited[size];
int color[size];
bool GraphJudge(int nodeNum)
{
memset(visited, 0, sizeof(visited));
memset(color, 0, sizeof(color));
for (int k = 0; k < nodeNum; k++)
{
if (visited[k] == 0)
{
visited[k] = 1;
color[k] = 1;
deque<int> q;
q.push_back(k);
while (q.empty()==false)
{
int i = q.front();
q.pop_front();
for (int j = 0; j < nodeNum; j++)
{
if (graph[i][j] > 0 && i!=j)
{
if (visited[j] == 0)
{
q.push_back(j);
visited[j] = 1;
color[j] = 1 - color[i];
}
else
{
if (color[j] == color[i])
return false;
}
}
}
}
}
}
return true;
}
int main(int argc, char* argv[])
{
ifstream in(".\\input.txt");
cin.rdbuf(in.rdbuf());
int T;
cin >> T;
cin.ignore();
for (int caseNum = 0; caseNum<T; caseNum++)
{
int M;
cin >> M;
memset(graph, 0, sizeof(&graph));
map<string, int> nameIndex;
map<string, int>::iterator it;
int nodecount = 0;
for (int i = 0; i < M; i++)
{
int start, end;
string p;
cin >> p;
it = nameIndex.find(p);
if (it == nameIndex.end())
{
nameIndex[p] = nodecount;
nodecount++;
}
start = nameIndex[p];
cin >> p;
it = nameIndex.find(p);
if (it == nameIndex.end())
{
nameIndex[p] = nodecount;
nodecount++;
}
end = nameIndex[p];
graph[start][end] = 1;
}
if (GraphJudge(nodecount))
cout << "Case #" << caseNum + 1 << ":" << "Yes" << endl;
else
cout << "Case #" << caseNum + 1 << ":" << "No" << endl;
}
system("pause");
return 0;
}
Problem 2:
问题二确切的说应该算作一个高中物理题,给出斜抛初速度和距离,计算斜抛初始角度。
#include<iostream>
#include <math.h>
#include <iomanip>
#include <ostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
//ifstream in("C:\\Users\\zhengyi\\Desktop\\ConsoleApplication1\\Debug\\input.txt");
//streambuf *cinbuf = cin.rdbuf(); //save old buf
//cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
//ofstream out("C:\\Users\\zhengyi\\Desktop\\ConsoleApplication1\\Debug\\out.txt");
//streambuf *coutbuf = std::cout.rdbuf(); //save old buf
//cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
//std::cin.rdbuf(cinbuf); //reset to standard input again
//std::cout.rdbuf(coutbuf); //reset to standard output again
int T;
cin >> T;
int k = 0;
while (k < T)
{
int V, D;
cin >> V >> D;
double theta = asin(9.8 * D / (V * V)) * 90 / 3.14159265;
cout << "Case #" << k + 1 <<":"<< fixed << setprecision(7) << theta << endl;
k++;
}
return 0;
}
Problem 3:
第三题操作过程是一种相似于插入排序的排序机制,对于接下来的元素。须要往前插入的话就耗费1$。以此计算总共花费。
#include <iostream>
#include <string>
#include <vector>
#include <ostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
//ifstream in("C:\\Users\\zhengyi\\Desktop\\ConsoleApplication1\\Debug\\input.txt");
//streambuf *cinbuf = cin.rdbuf(); //save old buf
//cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
//ofstream out("C:\\Users\\zhengyi\\Desktop\\ConsoleApplication1\\Debug\\out.txt");
//streambuf *coutbuf = std::cout.rdbuf(); //save old buf
//cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
//std::cin.rdbuf(cinbuf); //reset to standard input again
//std::cout.rdbuf(coutbuf); //reset to standard output again
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
int n;
cin >> n;
int count = 0;
cin.sync();
string str;
vector<string> v1;
while (count<n)
{
getline(cin, str);
v1.push_back(str);
count++;
}
//v1.erase(v1.begin());
int cost = 0;
for (int k = 1; k < n; k++)
{
string key = v1[k];
int t = k - 1;
if (t >= 0 && v1[t].compare(key) > 0)
{
v1[t + 1] = v1[t];
t--;
cost++;
}
v1[t + 1] = key;
}
cout << "Case #" << i + 1 << ":" << cost << endl;
}
return 0;
}
三道题目的代码
https://github.com/ncepuzhengyi/jobHuntingExam
以下这个是另外一次google的笔试题目。仅仅收集到了这一道
Problem 4
S0 = ”
S1 = ‘0’
S2 = ‘001’
S3 = ‘0010011’
S4 = ‘001001100011011’
……
SN = SN + ‘0’ + not(reverse( SN ))
reverse是字符串反转
not是0,1转换
求S1010000 的第k个数
small data set: k<105
large data set: k<1018
from math import log
from math import ceil
def Nlen(n):
return pow(2,n)-1
def LineNum(k):
return ceil(log(k+1,2))
r=True
def func(x):
global r
lastNum=LineNum(x)
if x==pow(2,lastNum-1):
if r:
return '0'
else:
return '1'
if x==1:
if r:
return '1'
else:
return '0'
if r:
r=False
else:
r=True
return func(pow(2,lastNum)-x)
s4=''
for i in range(1,16):
r=True
s4+=func(i)
print(s4)
Google笔试(2015年8月)的更多相关文章
- TIOBE 2015年7月编程语言排行榜:C++的复兴
TIOBE 2015年7月编程语言排行榜:C++的复兴 发表于2015-07-13 17:03| 16086次阅读| 来源CSDN| 128 条评论| 作者钱曙光 编程语言排行榜TIOBEC++ 摘要 ...
- 2015年3月阿里内推(c++研发)实习生电面经历
2015年3月开学开始就听说阿里会有内推,果不其然在师兄的引荐下推了菜鸟网络,但是在学校的BBS上看到了阿里云部门,而且要会C++,这使我更感兴趣,重新选择了方向,当然最后选择了阿里云.在此分享一下三 ...
- 2015年12月28日 Java基础系列(六)流
2015年12月28日 Java基础系列(六)流2015年12月28日 Java基础系列(六)流2015年12月28日 Java基础系列(六)流
- 2015年12月13日 spring初级知识讲解(四)面向切面的Spring
2015年12月13日 具体内容待补充...
- 2015年8月18日,杨学明老师《技术部门的绩效管理提升(研讨会)》在中国科学院下属机构CNNIC成功举办!
2015年8月18日,杨学明老师为中国网络新闻办公室直属央企中国互联网络中心(CNNIC)提供了一天的<技术部门的绩效管理提升(研讨会)>培训课程.杨学明老师分别从研发绩效管理概述.研发绩 ...
- 2015年8月17日,杨学明老师《产业互联网化下的研发模式转型》在中国科学院下属机构CNNIC成功举办!
2015年8月17日,杨学明老师为中国网络新闻办公室直属央企中国互联网络中心(CNNIC)提供了一天的<产业互联网化下的研发模式转型>内训课程.杨学明老师分别从产业互联网化的问题与挑战.传 ...
- 【C++】命令行Hangman #2015年12月15日 00:20:27
增加了可以在构造Hangman对象时通过传入参数设定“最大猜测次数”的功能.少量修改.# 2015年12月15日 00:20:22 https://github.com/shalliestera/ha ...
- 我的Python成长之路---第一天---Python基础(作业2:三级菜单)---2015年12月26日(雾霾)
作业二:三级菜单 三级菜单 可一次进入各个子菜单 思路: 这个题看似不难,难点在于三层循环的嵌套,我的思路就是通过flag的真假来控制每一层的循环的,简单来说就是就是通过给每一层循环一个单独的布尔变量 ...
- 我的Python成长之路---第一天---Python基础(作业1:登录验证)---2015年12月26日(雾霾)
作业一:编写登录接口 输入用户名密码 认证成功系那是欢迎信息 输错三次后锁定 思路: 1.参考模型,这个作业我参考了linux的登录认证流程以及结合网上银行支付宝等锁定规则 1)认证流程参考的是Lin ...
随机推荐
- Shell(五)Shell输入/输出重定向
Shell 输入/输出重定向 大多数 UNIX 系统命令从你的终端接受输入并将所产生的输出发送回到您的终端.一个命令通常从一个叫标准输入的地方读取输入,默认情况下,这恰好是你的终端.同样,一个命令 ...
- echarts图表属性说明
参考博客: https://blog.csdn.net/luanpeng825485697/article/details/76691965
- Spring Boot 启动的时候遇到 java.lang.ClassNotFoundException: ch.qos.logback.classic.Level
在刚开始接触spring boot的时候,想创建一个Hello World 的project. 但是创建完之后,Run as 'Spring Boot APP'的时候遇到这个错误. Level类存在于 ...
- GitHub上搭建私人hexo博客操作教程
GitHub上搭建hexo博客 安装GitGit:主要用于上传博客页面到github和命令操作安装NodeNode.js:Hexo的运行环境安装HexoHexo:博客程序打开安装Git后的生成的右键菜 ...
- FastDFS架构
1.什么是 FastDFS FastDFS是用c语言编写的一款开源的分布式文件系统.FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用Fas ...
- VC6.0VB6.0 Scratch等软件
VC6.0VB6.0 Scratch等软件 http://pan.baidu.com/s/1nv4hJrb
- Picking up Jewels
Picking up Jewels There is a maze that has one entrance and one exit. Jewels are placed in passages ...
- LintCode-交叉字符串
给出三个字符串:s1.s2.s3,推断s3是否由s1和s2交叉构成. 您在真实的面试中是否遇到过这个题? Yes 例子 比方 s1 = "aabcc" s2 = "dbb ...
- POJ 3664 Election Time 题解
这道题网上非常多人都会说easy,水题之类的话,只是我看了下说这种话的人的程序,能够说他们的程序都不及格! 为什么呢?由于他们的程序都是使用简单的二次排序水过(大概你能搜索到的多是这种程序).那样自然 ...
- zzulioj--1799--wrz的压岁钱(贪心)
1799: wrz的压岁钱 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 407 Solved: 71 SubmitStatusWeb Boa ...