题目

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)

[zoj] 4178. Killing the Brute-force的更多相关文章

  1. 小白日记46:kali渗透测试之Web渗透-SqlMap自动注入(四)-sqlmap参数详解- Enumeration,Brute force,UDF injection,File system,OS,Windows Registry,General,Miscellaneous

    sqlmap自动注入 Enumeration[数据枚举] --privileges -U username[CU 当前账号] -D dvwa -T users -C user --columns  [ ...

  2. nginx 1.3.9/1.4.0 x86 Brute Force Remote Exploit

    测试方法: 本站提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负! #nginx 1.3.9/1.4.0 x86 brute force remote exploit # copyri ...

  3. SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意  ...

  4. Test SRM Level Three: LargestCircle, Brute Force

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3005&rd=5858 思路: 如果直接用Brute F ...

  5. 安全性测试入门:DVWA系列研究(一):Brute Force暴力破解攻击和防御

    写在篇头: 随着国内的互联网产业日臻成熟,软件质量的要求越来越高,对测试团队和测试工程师提出了种种新的挑战. 传统的行业现象是90%的测试工程师被堆积在基本的功能.系统.黑盒测试,但是随着软件测试整体 ...

  6. HDU 6215 Brute Force Sorting(模拟链表 思维)

    Brute Force Sorting Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  7. hdu6215 Brute Force Sorting

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6215 题目: Brute Force Sorting Time Limit: 1000/100 ...

  8. HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting

    Brute Force Sorting Time Limit: 1 Sec  Memory Limit: 128 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  9. 「暑期训练」「Brute Force」 Restoring Painting (CFR353D2B)

    题意 给定一定条件,问符合的矩阵有几种. 分析 见了鬼了,这破题谁加的brute force的标签,素质极差.因为范围是1e5,那你平方(枚举算法)的复杂度必然爆. 然后你就会思考其中奥妙无穷的数学规 ...

随机推荐

  1. OpenJudge 1.5.24 正常血压

    24:正常血压 总时间限制: 1000ms 内存限制: 65536kB 描述 监护室每小时测量一次病人的血压,若收缩压在90 - 140之间并且舒张压在60 - 90之间(包含端点值)则称之为正常,现 ...

  2. IdentityServer4登录后无法跳转设置策略

    在中间件中手动改变samesite属性为lax就可以解决问题: services.Configure<CookiePolicyOptions>(options => { option ...

  3. ubuntu 安装及配置Apache

    一.下载.启动apache2 sudo apt-get install apache2 sudo /etc/init.d/apache2 restart 二.修改配置文件 1.更改网站根目录 sudo ...

  4. Java常用类的使用

    Java常用类 1. Optional 在我们的开发中,NullPointerException可谓是随时随处可见,为了避免空指针异常,我们常常需要进行 一 些防御式的检查,所以在代码中常常可见if( ...

  5. springMVC配置时,静态资源和jsp文件路径没错但是访问时controller的请求报404错误。

    springMVC配置时,静态资源和jsp文件路径没错但是访问时controller的请求报404错误. 1.场景 如果在web.xml中servlet-mapping的url-pattern设置的是 ...

  6. 以软件定义物联网芯片,以技术融合推动LPWAN2.0泛在物联

    作为数字化产业重要的基础设施之一,物联网迎来了黄金发展期.物联网通信技术通过数据的采集.分析.输出,从浅层次的互联工具和产品深化,到成为重塑生产组织方式的基础设施和关键要素,正深刻地改变着传统产业形态 ...

  7. Bugly iOS自动导入符号表

      前言       最近在处理Bugly问题的时候顺便解决了下符号表上传的问题,使用最新的上传工具包,也是顺便整理了下可以使用的脚本添加到了项目中,把这个过程中遇到的问题总结出来,脚本也会给出来,实 ...

  8. CentOS7使用yum方式安装Containerd

    # 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的 yum install -y yum-utils device-m ...

  9. 使用logstash同步Mysql数据表到ES的一点感悟

    针对单独一个数据表而言,大致可以分如下两种情况: 1.该数据表中有一个根据当前时间戳更新的字段,此时监控的是这个时间戳字段 具体可以看这个文章:https://www.cnblogs.com/sand ...

  10. 工业互联网领域的企业,都已经接入了ERP或者MES系统了吗?

    肯定不是得啊!之前的两化,后来的企业上云,到当下的智能制造.数字化转型,不都是想把制造业(也就是你说的工业互联网企业)往这个方向推么,ERP和MES是企业数字化的一部分,但不是全部,当然有的企业(小工 ...