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---- ...
随机推荐
- CLR via C#(02)-基元类型、引用类型、值类型
http://www.cnblogs.com/qq0827/p/3281150.html 一. 基元类型 编译器能够直接支持的数据类型叫做基元类型.例如int, string等.基元类型和.NET框架 ...
- HTML+CSS页面滚动效果处理
HTML+CSS代码如下: <!doctype html> <html> <head> <meta charset="utf-8"> ...
- 终于看完<LEARNING SQL>第二版,立此存照
- java Integer == 比较的小问题
示例代码: @Test public void testEquals() { Integer a = 127; Integer b = 127; if(a == b) { System.out.pri ...
- CocoaPods安装和使用教程(转摘)
Code4App 原创文章.转载请注明出处:http://code4app.com/article/cocoapods-install-usage 目录 CocoaPods是什么? 如何下载和安装Co ...
- WCF批量打开服务
WCF服务.利用循环,读取配置文件,打开所有的代理服务 和关闭代理服务的方法 //list列表 ,用于存储打开的服务列表 List<ServiceHost> _host = new Lis ...
- hdu 4023 2011上海赛区网络赛C 贪心+模拟
以为是贪心,结果不是,2333 贪心最后对自己绝对有利的情况 点我 #include<cstdio> #include<iostream> #include<algori ...
- sublime text 2中Emmet8个常用的技巧
原文链接:http://blog.csdn.net/lmmilove/article/details/9181323 因为开始做web项目,所以最近在用sublime编辑器,知道了一个传说中的emme ...
- T-SQL 使用WITH高效分页
一.WITH AS 含义 WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到.有的时候, ...
- SQLserver删除某数据库中所有表 方法 二
方便删除数据库中所有的数据表,清空数据库,有些有约束,不能直接delete,需要先删除库中的约束,代码如下: --删除所有约束DECLARE c1 cursor for select 'alter t ...