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 ...
随机推荐
- VUE:过滤器及日期格式化moment库
VUE:过滤器及日期格式化moment库 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...
- 20130912.Windows下常用命令的使用(不断更新)
Win+R================================ cmd => 命令行 lpksetup => 弹出安装或者卸载Windows显示语言 ipconfig => ...
- tp框架报错 Namespace declaration statement has to be the very first statement in the script
Namespace declaration statement has to be the very first statement in the script tp框架报这个错误,错误行数就是nam ...
- Maven系列--web.xml 配置详解
一 .web.xml介绍 启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 紧接着,容 ...
- 【codeforces 734F】Anton and School
[题目链接]:http://codeforces.com/problemset/problem/734/F [题意] 给你两个数组b和c; 然后让你找出一个非负数组a满足题中所给关系; [题解] 有个 ...
- unity3d 延迟运行脚本语句
在Unity3D中.有yield语句它负责延迟操作,yield return WaitForSeconds(3.0); //等待 3 秒 查看unity3d脚本手冊,使用方法须要在对应的格式. 以下代 ...
- 浅谈关于collection接口及相关容器类(一)
Collection在英文单词的意思是:採集,收集. 而在JAVA API 文档中它是一个收集数据对象的容器. Collection作为容器类的根接口.例如以下图(部分子接口未写出): waterma ...
- bzoj2734【HNOI2012】集合选数
2734: [HNOI2012]集合选数 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 831 Solved: 487 [Submit][Stat ...
- JS冒泡事件 与 事件捕获
JS冒泡事件 与 事件捕获 案例 <!DOCTYPE html> <html> <head> <title>冒泡事件</title> < ...
- js小结2
1.includes和contains 对于字符串,数组来说,判断包含是includes,对classList是contains 2.编辑span内容,enter提交(如何避免keydown之后换行: ...