2017微软秋季校园招聘在线编程笔试-#1402 : MS Recognition
来源:互联网 发布:什么软件可以备份数据 编辑:程序博客网 时间:2024/05/21 10:18
http://hihocoder.com/problemset/problem/1402
题意理解:M和S都很大,并且相互离的很远,M和S的两个端点不一样,M不平衡,所以端点的中点到重心的距离和端点的距离比值》0.5就是M。很奇怪为什么画一条支线看个数会不行,或者是参数设置的不好?
急转弯:端点和重心,距离关系
算法:bfs找端点
数据结构:无
from __future__ import print_function##'dfs and math'__author__ = 'hjkruclion'import sysimport mathdef read_int(): return list(map(int, sys.stdin.readline().split()))def read_str(): return sys.stdin.readline().split()[0]maxn = 500 + 100dx = [-1, -1, -1, 0, 1, 1, 1, 0]dy = [-1, 0, 1, 1, 1, 0, -1, -1]def dcmp(x): if math.fabs(x) < 1e-4: return 0 if x > 0: return 1 return -1a = [['.' for j in range(maxn)] for i in range(maxn)]vis = [[0 for j in range(maxn)] for i in range(maxn)]G = []N, M = read_int()for i in range(N): a[i] = read_str() # for j in range(M): # a[i][j] = t[j] # if i <= 5: # print(len(a[i]))# print(a[7][7] == '#')resM = 0resS = 0def calcu(x, y, x1, y1, x2, y2): if x1 == x2: if dcmp((x1 - x)) == 0: return 1 elif dcmp((x1 - x)) > 0: return 1 else: return -1 else: t = (y2 - y1) / (x2 - x1) * (x - x1) + y1 - y if dcmp(t) > 0: return 1 elif dcmp(t) == 0: return 1 else: return -1def dist(x1, y1, x2, y2): return math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))def bfs(xs, ys, tag): global G, vis q = [(xs, ys)] vis[xs][ys] = tag ansx = xs ansy = ys if tag == 1: G.append((xs, ys)) while(len(q) != 0): x, y = q.pop(0) for k in range(8): nx = x + dx[k] ny = y + dy[k] if nx >= 0 and nx < N and ny >= 0 and ny < M and vis[nx][ny] != tag and a[nx][ny] == '#': q.append((nx, ny)) vis[nx][ny] = tag if tag == 1: G.append((nx, ny)) ansx = nx ansy = ny return ansx, ansyfor i in range(N): for j in range(M): if vis[i][j] != 0 or a[i][j] == '.': continue # print('hh') G = [] x1, y1 = bfs(i, j, 1) x2, y2 = bfs(x1, y1, 2) num = len(G) ans = 0 zx = 0 zy = 0 for _ in range(num): # ans += calcu(G[_][0], G[_][1], x1, y1, x2, y2) zx += G[_][0] zy += G[_][1] zx /= num zy /= num dist1 = dist(zx, zy, (x1 + x2) / 2, (y1 + y2) / 2) dist2 = dist(x1, y1, x2, y2) if dist1 / (dist2 / 2) >= 0.5: resM += 1 else: resS += 1 # if math.fabs(ans) >= num / 2: # resM += 1 # else: # resS += 1print(resM, resS)
阅读全文
0 0
- 2017微软秋季校园招聘在线编程笔试-#1402 : MS Recognition
- 2017微软秋季校园招聘在线编程笔试
- 2017微软秋季校园招聘在线编程笔试 Composition
- 2017微软秋季校园招聘在线编程笔试
- 2017微软秋季校园招聘在线编程笔试 Composition (DP)
- 2017微软秋季校园招聘在线编程笔试(第二题)
- 2017微软秋季校园招聘在线编程笔试(第三题)
- 2017微软秋季校园招聘在线编程笔试-#1400 : Composition
- 2017微软秋季校园招聘在线编程笔试 题目2 Composition
- 2017微软秋季校园招聘在线编程笔试(第一题)
- 2017微软秋季校园招聘在线编程笔试-#1399 : Shortening Sequence
- 2017微软秋季校园招聘在线编程笔试-#1401 : Registration Day
- 阿里巴巴2015秋季校园招聘研发工程师在线笔试题
- 微软2014校园招聘笔试编程题
- 2017校园招聘腾讯笔试题 在线编程题
- 阿里巴巴2014年校园招聘(秋季招聘)在线笔试--测试研发工程师
- 题目1 : Magic Box【微软2016校园招聘在线笔试】
- 微软2016校园招聘在线笔试: [Islands Travel]
- Qt 学习之路 2(19):事件的接受与忽略
- 支付宝生活号已激活但自动登录提示没权限,什么原因
- 北京赛区(2017)网络赛-I-线段树
- 编译型与解释型、动态语言与静态语言、强类型语言与弱类型语言的区别
- html之a标签不能嵌套a标签及解决方案
- 2017微软秋季校园招聘在线编程笔试-#1402 : MS Recognition
- 16秋计算机JAVA第一节课作业(钟永钜)
- cmd运行class文件提示“错误: 找不到或无法加载主类”
- day59-struts2_01:笔记。----【框架就是jar包】而已
- 大端与小端
- 使用JavaScript编写原生态的Ajax
- 深度分析Rabbitmq在openstack中的实现
- BUG集锦
- 【Java】中断