csu oj 1344: Special Judge
Description
Given a positive integer n, find two non-negative integers a, b such that a2 + b2 = n.
Input
The first line contains the number of test cases T (1 <= T <= 1000).
For each test case, there is only one line with an integer n (1 <= n <= 109) as defined above.
Output
For each test case, output two integers a, b separated by a single space such that a2 + b2 = n. If there are multiple solutions, anyone will be accepted. If there is no solution, output “-1” (without quotation marks) instead.
Sample Input
Sample Output
-
Hint
还记得我们在“A Sample Problem”中说到的OJ的判题形式吗?这个题主要让我们来熟悉一下OJ的另一种名为Special Judge的判题形式。所谓的Special Judge是指OJ将使用一个特定的程序来判断我们提交的程序的输出是不是正确的,而不是单纯地看我们提交的程序的输出是否和标准输出一模一样。
一般使用Special Judge都是因为题目的答案不唯一,更具体一点说的话一般是两种情况:
(1)题目最终要求我们输出一个解决方案,而且这个解决方案可能不唯一。比如这个题目就是这样的,只要求我们输出一组a、b满足a^2 + b^2 = n,而对于不同的n,可能有多组a、b满足这一条件,像n=4时,就有a=2、b=0和a=0、b=2这两组解,这时我们输出任意一组解都可以。
(2)题目最终要求我们输出一个浮点数,而且会告诉我们只要我们的答案和标准答案相差不超过某个较小的数就可以,比如0.000001。这种情况我们只要保证我们的中间运算过程尽可能精确就可以了,并且最后输出答案的时候保留的小数位数足够多就行了,比如如果要求我们的答案和标准答案相差不超过0.01,那么一般我们保留3位小数、4位小数等等都是可以的,而且多保留几位小数也没什么坏处。
为了能让大家更清楚的了解Special Judge的原理,这里我把这个题目的执行Special Judge功能的程序的源代码贴出来了
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
using namespace std;
int main()
{
int t,n,a,b;
cin>>t; while(t--)
{
bool flag=false;
cin>>n;
for(int a=;a*a<=n/;a++)
{
b=sqrt(n-a*a);
if(a*a+b*b==n)
{
flag=true;
break;
}
}
if(flag)
cout<<a<<" "<<b<<endl;
else
cout<<"-1"<<endl; }
return ;
}
csu oj 1344: Special Judge的更多相关文章
- 如何给LOJ补全special judge
首先你要会写一个叫$data.yml$的东西, 这里面记录了这道题的$subtask$计分策略 也告诉了评测姬这道题是提交答案还是$spj$还是交互题 那么,$YAML$语言是啥啊? 别问我,我也不会 ...
- 【教程】如何正确的写一个Lemon/Cena的SPJ(special judge)
转自:http://www.cnblogs.com/chouti/p/5752819.html Special Judge:当正确的输出结果不唯一的时候需要的自定义校验器 首先有个框架 #includ ...
- Special Judge Ⅱ
Problem Description Q:什么是 Special Judge,Special Judge 的题目有什么不同? A:一个题目可以接受多种正确答案,即有多组解的时候,题目就必须被 Spe ...
- CSU OJ 1340 A Sample Problem
Description My girlfriend loves 7 very much, she thinks it is lucky! If an integer contains one or m ...
- [zt]OJ常见的Judge Status
Queuing : 提交太多了,OJ无法在第一时间给所有提交以评判结果,后面提交的程序将暂时处于排队状态等待OJ的评判.不过这个过程一般不会很长. Compiling : 您提交的代码正在被编译. R ...
- csu oj 1339: 最后一滴血
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1339 1339: 最后一滴血 Time Limit: 1 Sec Memory Limit: 1 ...
- csu oj 1330 字符识别?
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1330 1330: 字符识别? Time Limit: 1 Sec Memory Limit: 1 ...
- csu oj 1811: Tree Intersection (启发式合并)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1811 给你一棵树,每个节点有一个颜色.问删除一条边形成两棵子树,两棵子树有多少种颜色是有 ...
- csu oj 1804: 有向无环图 (dfs回溯)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1804 中文题意就不说了. dfs从底到根回溯即可,看代码应该能清楚. //#pragma ...
随机推荐
- Ubuntu关机时间过长,总是停在logo界面
有时候我们总能遇到ubuntu关机的时候卡住,无法关机,一查看发现是" a stop job is running..." 然后后面接着一串等待时间. 这时候我们需要修改一下sys ...
- 洛谷P2782 友好城市 DP
やはり まだあしたということは嘘でしょう.ぜんぶ忘れた( ´・ヮ・`) 所以今天就贴一道水题吧 原题>>https://www.luogu.org/problem/show?pid=278 ...
- 洛谷P2362 围栏木桩----dp思路
在翻dp水题的时候找到的有趣的题0v0 原文>>https://www.luogu.org/problem/show?pid=2362<< 题目描述 某农场有一个由按编号排列的 ...
- Linux 命令之mv
mv命令也是Linux中很常见命令 作用:可以用来移动文件或者将文件改名 命令格式: mv [选项] 源文件或目录 目标文件或目录 命令参数: -b :若需覆盖文件,则覆盖前先行备份. -f :for ...
- Windows下使用命令安装Python的scipy库出错的解决
平时使用Python都是在Sublime下使用,不想使用IDE.使用各种库时安装也就是使用pip安装即可.来说说今天自己遇到的一个问题:使用scipy数学库时,使用命令: pip install sc ...
- codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
题目链接:Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 第一次写\(dsu\ on\ tree\),来记录一下 \(dsu\ o ...
- android 利用CountDownTimer实现时分秒倒计时效果
https://blog.csdn.net/mrzhao_perfectcode/article/details/81289578
- django认证系统 Authentication
Django自带一个用户认证系统,用于处理用户账户.群组.许可和基于cookie的用户会话. Django的认证系统包含了身份验证和权限管理两部分.简单地说,身份验证用于核实某个用户是否合法,权限管理 ...
- 封装sqlhelper【一】
控件信息展示: //定义调用数据库类文件 namespace SqlHelper { public class TblClass { public int classId { get; set; } ...
- 学习笔记31—endnote设置
修改文献引用设置: JournalArticle: Author. (Year). Title. [Translated Title]. [Reviewed Item]. Journal|, Volu ...