楼主: peter668
跳转到指定楼层
上一主题 下一主题
收起左侧

Google电面面经

🔗
robinho364 2014-5-19 13:29:15 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
robinho364 2014-5-19 14:04:49 | 只看该作者
全局:
readman 发表于 2014-5-19 13:14
大概是这意思把..
添加的node是字母, 不是string, 添加前还要先找到位置 避免在字典中重复出现字母.
估 ...

Hi,根据lz的例子,简单地写了一下,监测结果是:
b
f
a
c
t
d
  1. #define _USE_MATH_DEFINES

  2. #ifdef ONLINE_JUDGE
  3. #define FINPUT(file) 0
  4. #define FOUTPUT(file) 0
  5. #else
  6. #define FINPUT(file) freopen(file,"r",stdin)
  7. #define FOUTPUT(file) freopen(file,"w",stdout)
  8. #endif

  9. #include <iostream>
  10. #include <cstdio>
  11. #include <cstring>
  12. #include <cstdlib>
  13. #include <cmath>
  14. #include <ctime>
  15. #include <set>
  16. #include <stack>
  17. #include <string>
  18. #include <map>
  19. #include <vector>
  20. #include <queue>
  21. #include <algorithm>
  22. #include <functional>

  23. typedef long long ll;
  24. static const int M = 300;
  25. static const int N = 10;
  26. static const int LEN = 1000010;
  27. static const int MAX = 0x7fffffff;
  28. static const int MIN = ~MAX;
  29. static const double EPS = 1e-7;
  30. char arr[N][M];
  31. int indegree[N];
  32. std::vector< std::map<int, int> > alphabet(27);

  33. void topologic_sort(int n)
  34. {
  35.         std::queue<int> cur;
  36.         std::vector<int> out;

  37.         for (int i = 1; i<n; i++){
  38.                 if (indegree[i] == 0 && alphabet[i].size() != 0){
  39.                         cur.push(i);
  40.                         out.push_back(i);
  41.                 }
  42.         }

  43.         int ncount = 0;
  44.         while (cur.empty() == false){
  45.                 int tmp = cur.front();
  46.                 cur.pop();
  47.                 ncount++;
  48.                 std::map<int, int>::iterator it = alphabet[tmp].begin();
  49.                 for (it = alphabet[tmp].begin(); it != alphabet[tmp].end(); it++) {
  50.                         if (--indegree[it->second] == 0){
  51.                                 cur.push(it->second);
  52.                                 out.push_back(it->second);
  53.                         }
  54.                 }
  55.         }

  56.         for (int i = 0; i < out.size(); i++) {
  57.                 printf("%c\n", out[i] + 'a' - 1);
  58.         }
  59. }


  60. void solve(int n, int m)
  61. {
  62.         for (int i = 0; i < m; i++) {
  63.                 scanf("%s", arr[i]);
  64.         }

  65.         char *prev_str = arr[0];
  66.         size_t prev_len = strlen(prev_str);
  67.         for (int i = 1; i < m; i++) {
  68.                 size_t len = std::min(prev_len, strlen(arr[i]));
  69.                 for (int j = 0; j < len; j++) {
  70.                         if (prev_str[j] != arr[i][j]) {
  71.                                 int prev = prev_str[j] - 'a' + 1;
  72.                                 int cur = arr[i][j] - 'a' + 1;
  73.                                 if (alphabet[prev][cur] == 0) {
  74.                                         alphabet[prev][cur] = cur;
  75.                                         indegree[cur]++;
  76.                                 }
  77.                                 break;
  78.                         }
  79.                 }
  80.                 prev_str = arr[i];
  81.                 prev_len = len;
  82.         }

  83.         topologic_sort(27);

  84.         for (int i = 0; i<n; i++){
  85.                 alphabet[i].clear();
  86.         }

  87. }

  88. int main()
  89. {
  90.         FINPUT("in.txt");
  91.         FOUTPUT("out.txt");

  92.         int n, m;
  93.         while (scanf("%d %d ", &n, &m) != EOF) {
  94.                 solve(n, m);
  95.         }
  96.         return 0;
  97. }
复制代码

评分

参与人数 1大米 +5 收起 理由
readman + 5 这么快就写出来了啊. 赞一个

查看全部评分

回复

使用道具 举报

🔗
sj1456 2014-5-20 05:26:04 | 只看该作者
全局:
discoveryi 发表于 2014-5-19 11:49
***************************************************************
GOOGLE PHONE TECHNICAL INTERVIEW  ...

碉堡,谢拉兄台!
回复

使用道具 举报

全局:
想问一下第二题  数组最后一个数据 tdf 感觉会造成图里有环呀 这样还能拓扑排序么? 还是lz手抖打错啦?

下周可能要电面G 图相关的还有点弱。。好好准备了。。
回复

使用道具 举报

🔗
shinichish 2014-9-22 08:25:12 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
tbian 2014-10-15 03:12:46 | 只看该作者
全局:
可以简单解释一下怎么做吗
回复

使用道具 举报

🔗
xdrealmadrid 2014-10-31 03:41:30 | 只看该作者
全局:
topological sort正解
回复

使用道具 举报

🔗
danielle147 2015-5-30 10:08:29 | 只看该作者
本楼:
全局:
mark 一个~
回复

使用道具 举报

🔗
volcano 2015-6-5 17:15:56 | 只看该作者
全局:
littlecoolblaxk 发表于 2014-9-21 02:57
想问一下第二题  数组最后一个数据 tdf 感觉会造成图里有环呀 这样还能拓扑排序么? 还是lz手抖打错啦?

...

我也觉得楼主打错了, 这里面有环
回复

使用道具 举报

🔗
chwcrazy 2015-6-19 02:02:18 | 只看该作者
全局:
如果没有tdf  这条路径(排除环)的话,应该是 afctbpk(在没给全所有node的条件下算的)当然 Topological Sorting答案不唯一

补充内容 (2015-6-18 13:20):
应该是['a', 'f', 'c', 't', 'p', 'b', 'd', 'k'], 如果没有tdf的话
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表