Codeforce - Runtime Error
Bahosain was trying to solve this simple problem, but he got a Runtime Error on one of the test cases, can you help him by solving it?
Given an array of N non-negative integers and an integer K, your task is to find two integers X and Y from the given array such that X × Y = K.
The chosen numbers must have different indices in the array.
Input
The first line of input contains T (1 ≤ T ≤ 128), the number of test cases.
The first line of each test case contains two integers: N (2 ≤ N ≤ 100,000) and K (1 ≤ K ≤ 100,000). The next line contains N space-separated integers, each between 0 and 100,000.
Output
For each test case, if there is no solution, print -1 on a single line. Otherwise print a single line with two space-separated integers X Y (X ≤ Y), where X and Y are two numbers from the given array and X × Y = K.
If there is more than one possible solution, print the one with the minimum X.
Sample Input |
Sample Output |
||
4 |
2 6 |
||
6 12 |
-1 |
||
3 6 2 |
4 2 |
9 |
3 12 |
2 1 |
1 12 |
||
1 2 |
|||
4 36 |
|||
12 18 |
3 36 |
||
4 12 |
|||
1 2 6 |
12 |
这道题说多了都是泪,在WA了几道题的情况下跑到这道题来写,还写得很快,导致区间分错,哎,以后要多注意开闭区间啊,天呐!!!!
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
using namespace std; const int MX = 111111;
int num[MX];
int n, k; bool judge(int i, int mid)
{
if (num[i] * num[mid] >= k) return true;
else return false;
} int main()
{
//freopen("input.txt", "r", stdin);
int cas;
while (scanf("%d", &cas) != EOF)
{
while(cas--)
{
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
{
scanf("%d", &num[i]);
}
sort(num, num + n);
bool j = true;
for (int i = 0; i < n; i++)
{
int lower = i + 1;//就是它= =
int higher = n - 1;//它以后也要多留心!!!
while (lower <= higher)
{
int mid = (lower + higher) / 2;
if (judge(i, mid)) higher = mid - 1;
else lower = mid + 1;
}
if (num[lower] * num[i] == k)
{
j = false;
printf("%d %d\n", num[i], num[lower]);
break;
}
}
if (j) printf("-1\n");
}
}
return 0;
}
Codeforce - Runtime Error的更多相关文章
- com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind
在发布 web service 时报错: Endpoint.publish(publishAddress, hl7MessageReveiver); com.sun.xml.internal.ws.s ...
- Arcmap 安装完后使用出现visual fortran run-time error的解决方法
今天将ArcGIS安装到自己的XP笔记本上,安装过程一帆风顺,但打开Arcmap使用的时候,出现了visual fortran run-time error. 下面是解决方法: 下载个Dforrt.d ...
- Qt Sqlite qwt 发布过程中碰到的问题runtime error
qt版本:4.8.0 qwt版本:6.1.2 使用dll show检测缺少的dll,或者笨一点的方法,点击运行差什么找什么放进去: 左上显示exe调用哪些dll,右边是dll又再次调用啦哪些dll: ...
- IE Unknown runtime error
1. 在函数中使用原生的js的时候,有时在IE下会出现Unknown runtime error 火狐下正常 2. 解决办法, 将原生js改成jquery处理兼容问题 document.getElem ...
- Microsoft Visual C++ Runtime error解决方法
1: 当出现下图时提示Microsoft Visual C++ Runtime error 2:此时不要关闭该对话框,然后打开任务管理器(Ctrl+Shift+Esc)如下图: 找到Microsoft ...
- Microsoft Visual C++ Runtime Library Runtime Error的解决的方法
打开浏览器时,出现Microsoft Visual C++ Runtime Library Runtime Error错误,初步预计是软件冲突,可能有多种出错的方式,我的是浏览器自己主动关闭. 一. ...
- UVa 1402 Runtime Error 伸展树
Runtime Error 到现在连样例也跑不出来!!! 调试了一晚上快要死了…… 知道错在哪里但是不会改,代码先扔在这里吧.看来不能太依赖模板啊orz…… #include <cstdio&g ...
- Mindjet MindManager 2012 从模板创建出现“Runtime Error pure virtual function call” 解决方法
我的Mindjet MindManager 2012 Pro也就是MindManager10 在应用模板之后总会显示 Microsoft Visual C++ Runtime Library Runt ...
- mindmanager2012打开文件出现runtime error r6025 解决方式
关于mindmanager 2012启动无法执行,提示c++错误 ---------------------------Microsoft Visual C++ Runtime Library---- ...
随机推荐
- Jquery.Datatables 基本设置的中文注解
$(document).ready(function() { $('#example').dataTable({ "sScrollX": "100%", //表 ...
- 基于SNMP的路由拓扑发现算法收集
一.三层(网络层)发现 算法来源:王娟娟.基于SNMP的网络拓扑发现算法研究.武汉科技大学硕士学位论文,2008 数据结构: 待检路由设备网关链表:存放指定深度内待检路由设备的网关信息,处理后删除. ...
- Delphi管理多线程之线程局部存储:threadvar
尽管多线程能够解决许多问题,但是同时它又给我们带来了很多的问题.其中主要的问题就是:对全局变量或句柄这样的全局资源如何访问?另外,当必须确保一个线程中的某些事件要在另一个线程中的其他时间之前(或之后) ...
- Qt Designer 修改窗体大小改变控件位置
一.新建一个窗体 用qt designer 新建一个QWidget窗体, 在窗体中右键 选择布局, 发现布局是选择不了的,这个是因为窗体里面没有添加控件, 任意添加空间后便可选择 右键-- 布局-- ...
- ODATA WEB API(一)---扩展使用
一.概述 时间也算充足,抽点时间总结下OData的常用的使用方式,开放数据协议(OData)是一个查询和更新数据的Web协议.OData应用了web技术如HTTP.Atom发布协议(AtomPub)和 ...
- 【JAVA集合框架之Map】
一.概述.1.Map是一种接口,在JAVA集合框架中是以一种非常重要的集合.2.Map一次添加一对元素,所以又称为“双列集合”(Collection一次添加一个元素,所以又称为“单列集合”)3.Map ...
- 动软MySQL存储过程模板
<#@ template language="c#" HostSpecific="True" #><#@ output extension= ...
- ASP.NET 5探险(8):利用中间件、TagHelper来在MVC 6中实现Captcha
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:由于ASP.NET 5及MVC 6是一个微软全新重新的Web开发平台,之前一些现有的验 ...
- PDF解析记录——Pdfbox
此文仅作记录[嫌放电脑里碍事-_-],内容为以前收集的一小段代码. 下面为pdf获取文本的简要代码片段: private string GetPDFText(string filename) { ...
- JQuery EasyUI validatebox(验证框)
JQuery EasyUI validatebox(验证框) http://www.easyui.info/archives/602.html