def printindex(n,arr):
# n = int(input())
# arr = list(map(int,input().split(' ')))
li1=[]
li2=[]
for i in range(n):
if(arr[i]<0):
li1.append(i)
else:
li2.append(i)
index = 0
for i in li2:
for j in li1:
if abs(arr[i]>abs(arr[j])):
index +=abs(j-i)*abs(arr[j])
arr[i] = arr[i] -abs(arr[j])
arr[j] =0
else:
index +=abs(j-i)*abs(arr[i])
arr[j] = arr[j]+arr[i]
arr[i]=0
break
return index
# print(index)
if __name__ == '__main__':
test1 = {'l1': [5], 'l2': [5, -4, 1, -3,1], 'result': [9]}
# test2 = {'l1': [2, 2], 'l2': [4, 6], 'result': [4 ,2]}
test = [test1]
count = 0
for t in test:
if printindex(t['l1'], t['l2']) == t['result']:
count += 1
else:
print('l1:', t['l1'], '\nl2:', t['l2'], '\nOutput:', printindex(t['l1'], t['l2']), '\nExpect:',
t['result'])
print('Case通过率:', count * 100 / len(test), '%')

  

腾讯2019年暑期实习生招聘在线笔试技术研究和数据分析方向第二题(python)的更多相关文章

  1. 腾讯2019年暑期实习生招聘提前批在线笔试技术研究和数据分析方向t2(python)

    小Q有一叠纸牌,一共有n张,从上往下依次编号为1~n.现在小Q要进行以下重复操作:把位于顶端的牌扔掉,把新的顶端的牌放到这叠牌的底部.小Q会一直操作到只剩下一张牌为止,小Q想知道每次扔掉的牌的编号.[ ...

  2. hihocoder 网易游戏2016实习生招聘在线笔试 解题报告

    比赛笔试链接:http://hihocoder.com/contest/ntest2015april/problems 题目就不贴了. 1.推箱子. 思路:纯模拟. 代码(28MS): #includ ...

  3. 腾讯2017年暑期实习生编程题【算法基础-字符移位】(C++,Python)

     算法基础-字符移位 时间限制:1秒 空间限制:32768K 题目: 小Q最近遇到了一个难题:把一个字符串的大写字母放到字符串的后面,各个字符的相对位置不变,且不能申请额外的空间. 你能帮帮小Q吗? ...

  4. 微软2016校园招聘在线笔试-Professor Q's Software

    题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...

  5. 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...

  6. 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]

    传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...

  7. 微软2016校园招聘在线笔试 [Recruitment]

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A company plans to recruit some new employees. There are N ca ...

  8. 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场

    题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...

  9. 微软2016校园招聘在线笔试之Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

随机推荐

  1. EntityFramework Inner Exception Catch

    在保存时加入这一段,就可以查看error具体是哪里出错了.正式发布需要删除这段,try catch毕竟会影响性能 try { entity.SaveChanges(); } catch (DbEnti ...

  2. [转][C#]服务安装卸载命令

    c:\windows\microsoft.net\Framework\v2.0.50727\installutil.exe  [/u] X:\服务.exe

  3. Java定时器小实例

    有时候,我们需要在Java中定义一个定时器来轮询操作,比如每隔一段时间查询.删除数据库中的某些数据等,下面记录一下一种简单实现方式 1,首先新建一个类,类中编写方法来实现业务操作 public cla ...

  4. CentOS7.5 GlusterFS 分布式文件系统集群环境搭建

    环境准备: 系统版本:CentOS Linux release 7.5.1804 (Core) glusterfs:3.6.9 userspace-rcu-master: 硬件资源: 10.200.2 ...

  5. 2019年1月16日22:50:28 白糖SR1905

    很好的机会,只拿了点皮毛,如果说都是因为上班时间不充裕那是给自己找借口,最主要原因没别的:思维不清,策略不明- 这里的入场初衷是周线区间下沿,日线向下脱离中枢失败后回拉一笔,那么这一单的做法就应该很明 ...

  6. Sping Cloud项目启动报A component required a bean of type 'com.tianyan.bbc.dao.SecurityUserBaseMapper' that could not be found.

    项目构建正常,启动和Debug报以下错误: Error starting ApplicationContext. To display the conditions report re-run you ...

  7. kafka connect rest api

    1. 获取 Connect Worker 信息curl -s http://127.0.0.1:8083/ | jq lenmom@M1701:~/workspace/software/kafka_2 ...

  8. C语言数据结构基础学习笔记——树

    树是一种一对多的逻辑结构,树的子树之间没有关系. 度:结点拥有的子树数量. 树的度:树中所有结点的度的最大值. 结点的深度:从根开始,自顶向下计数. 结点的高度:从叶结点开始,自底向上计数. 树的性质 ...

  9. C# & JAVA:读写文件

    using System; using System.IO; using System.Text; namespace ConsoleApplication4 { class Program { pu ...

  10. 创建自定义的 Angular Schematics

    本文对 Angular Schematics 进行了介绍,并创建了一个用于创建自定义 Component 的 Schematics ,然后在 Angular 项目中以它为模板演练了通过 Schemat ...