Google笔试(2015年8月)
来源:互联网 发布:找对象软件靠谱吗 编辑:程序博客网 时间:2024/05/22 15:57
华电北风吹
天津大学认知计算与应用重点实验室
日期: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 5int 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
……
reverse是字符串反转
not是0,1转换
求
small data set: k<
large data set: k<
from math import logfrom math import ceildef Nlen(n): return pow(2,n)-1def LineNum(k): return ceil(log(k+1,2))r=Truedef 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)
0 0
- Google笔试(2015年8月)
- 2007年4月23日Google招聘笔试有感
- 2015年9月29笔试总结
- 先锋商泰笔试面试-2015年3月14
- 2015年3月荔枝FM前端笔试题
- 腾讯2015年3月实习生笔试题
- 2015年04月02日阿里笔试总结
- 华为秋招2017年8月笔试
- google笔试
- Google笔试
- Google笔试
- google笔试
- google笔试
- [笔试题目] 腾讯2015年9月基础研究笔试题
- [笔试题目] 美团2015年9月后端开发工程师笔试题
- Google2007年4月笔试题
- 【微软】2011年9月笔试题
- 2013年google 在线笔试第五题被虐记。。
- Android 保存View到本地SD卡
- 2016年 成渝校招软件上机练习
- Palindrome Number
- 操作系统过小,无法启动数据库
- TFHpple使用方法
- Google笔试(2015年8月)
- UVa 340 Master-Mind Hints
- 1090. Highest Price in Supply Chain (25)
- Java基础 笔记(2)
- hibernate一对一,一对多,多对一,多对多配置
- UVA 193 Graph Coloring
- Android 开源框架Universal-Image-Loader完全解析(三)
- Android ADB工具-管理设备 app(二)
- C++ 实现单例模式