题目

Chenjb is the task author of the 71-st Zhejiang Provincial Collegiate Programming Contest. He created an NP-Hard problem on a graph with n vertices, the intended solution of which is DFS with branching and pruning. Chenjb is an experienced task author, he knows that the constraints can't be too tight, so he will set the time limit t to be 3x, where x is the running time of the intended solution on the slowest test case.

Chenjb heard that the contest would be unfortunately held on Potato OJ, whose hardware is not so good. To protect Potato OJ from being overloaded and the contest being a failure, Chenjb plans to cut down the input size of his task. He has tested the running time of the intended solution and the brute-force solution for various values of n. Note that for simplicity, we assume the running time of the solutions on a test case only depends on the value of n.

Please help Chenjb find the smallest value of n such that 1≤nm, and the brute-force solution won't pass the problem. Note that if the time limit is t, we assume that a solution will pass if and only if its running time on each test case is smaller than or equal to t.

Input:

The input contains multiple cases. The first line of the input contains a single integer T (1≤T≤50), the number of cases.

For each case, the first line of the input contains a single integer m (1≤m≤50), denoting the upper bound of n.

The second line contains m integers a1,a2,…,a**m (1≤a**i≤100,a**ia**i+1), the i-th of which denotes the running time of the intended solution when n=i.

The third line contains m integers b1,b2,…,b**m (1≤b**i≤100,b**ib**i+1), the i-th of which denotes the running time of the brute-force solution when n=i.

Output:

For each case, print a single line containing a single integer denoting the minimum possible value of n. If there is no solution, print −1 instead.

Sample Input:

2
4
1 2 7 20
2 5 30 40
3
2 3 3
5 7 8

Sample Output:

3
-1

思路

该题目大意是在说Chenjb老师在为土豆OJ设计问题通过门槛,由于OJ硬件配置太低,没有办法运行太多用例。现需要裁剪用例个数,要求对每个问题求出过滤掉暴力算法时所需要的最少用例数量。

这个问题乍一看摸不着头脑,实际上却很简单。。。针对一道题目,从左到右遍历用例,找到第一个时间限制(3*理想用例耗时)小于暴力算法耗时的用例为止,已遍历用例的个数就是所需要的值。以示例中的第一道题目为例,从左到右遍历用例,遍历至第3个用例时,发现时间限制(3*7=21)小于暴力算法耗时(30),那么这道用例就能够把暴力算法过滤掉,因此最终结果为3。

代码

python代码:

T=input()
T=int(T)
for i in range(T):
m=input()
intend=input().split()
brute=input().split()
intend=[int(i) for i in intend]
brute=[int(i) for i in brute]
n=-1
for i in range(len(intend)):
if intend[i]*3 < brute[i]:
n=i+1
break
print(n)

最新文章

  1. CSS3 Flexbox轻松实现元素的水平居中和垂直居中
  2. SQL SERVER全面优化-------索引有多重要?
  3. 安装Visual Studio的插件AnkhSvn
  4. 让padding、border等不占据宽度
  5. Java学习笔记16--异常
  6. 工作常用的linux/mysql/php/工具命令
  7. sqlserver 2008 左补齐字符串
  8. Unity优化之纹理集
  9. Word Break II 解答
  10. cocos2d-x游戏开发系列教程-超级玛丽02-代码结构
  11. [笔记]cin、cout与scanf、printf的效率差异对比分析
  12. node+vue进阶【课程学习系统项目实战详细讲解】打通前后端全栈开发(1):创建项目,完成登录功能
  13. Backtrack无线攻防(很任性的一篇)
  14. Cherrypy文件上传非ASCII文件名乱码问题解决
  15. git ssh https 踩坑记 ---- 域账号密码更新
  16. maven安装cucumber的pom文件设置
  17. C#编程(五十一)----------链表
  18. Linux 网络编程-&gt;epoll&lt;-LT/ET模式整理(~相逢何必曾相识~)
  19. ASP.NET Core的身份认证框架IdentityServer4--(5)自定义用户登录(通过接口登录,无UI版本)
  20. python生成器 协程

热门文章

  1. 前端Long类型丢失精度问题
  2. CodeForces - 1701C
  3. ansible 003 常用模块
  4. mysql_阻塞和死锁
  5. kindeditor获取html内容之终极大法
  6. Django提交时报错
  7. Django ORM 实现数据的多表 增删改查
  8. 查询参数和字符串校验:Query_Parameters_and_String_Validations
  9. kibana安装安装插件
  10. 【设计模式】Java设计模式 - 命令模式