一般做法:

  显然的超内存

#include<stdio.h>
#include<algorithm>
using namespace std;
int a[],ans[];
int main()
{
int t,i,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n);
int j=,tmp=;
a[n++]=;
for(i=; i<n; i++)
{
if(a[i]==a[i-])
{
tmp++;
}
else
{
if(tmp!=)
ans[j++]=a[i-];
//printf("%d\n",tmp);
tmp=;
}
} printf("%d %d\n",ans[],ans[]);
}
return ;
}

正确做法:

  位运算

  计算出 a+b以及a*a+b*b

然后求根求出a 和 b

#include<stdio.h>
#include<string.h>
#include<math.h>
#define eps 1e-8
int b[];
__int64 bb[];
int main()
{
int i,n,t;
scanf("%d",&t);
while(t--)
{
int x;
__int64 xx;
memset(b,,sizeof(b));
memset(bb,,sizeof(bb));
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",&x);
xx=(__int64)x*x; int k=; while(x>)
{
b[k++]+=x%;
x>>=;
} k=;
while(xx>)
{
bb[k++]+=xx%;
xx>>=(__int64);
}
}
x=;
for(i=;i>=;i--)
{
//printf("%d ",b[i]);
x=(x<<)+b[i]%;
}
//printf("\n%d\n",x);
xx=;
for(i=;i>=;i--)
{
//printf("%lld ",bb[i]);
xx=(xx<<(__int64))+bb[i]%;
}
//printf("\n%I64d\n",xx);//(double)
int abs=sqrt((long double)(*xx-(__int64)x*x))+eps;
printf("%d %d\n",(x-abs)/,(x+abs)/);
}
return ;
}

C++提交

#include<stdio.h>
#include<string.h>
#include<math.h>
#define eps 1e-8
int b[];
__int64 bb[];
int main()
{
int i,n,t;
scanf("%d",&t);
while(t--)
{
int x;
__int64 xx;
memset(b,,sizeof(b));
memset(bb,,sizeof(bb));
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",&x);
xx=(__int64)x*x; int k=; while(x>)
{
b[k++]+=x%;
x>>=;
} k=;
while(xx>)
{
bb[k++]+=xx%;
xx>>=(__int64);
}
}
x=;
for(i=;i>=;i--)
{
//printf("%d ",b[i]);
x=(x<<)+b[i]%;
}
//printf("\n%d\n",x);
xx=;
for(i=;i>=;i--)
{
//printf("%lld ",bb[i]);
xx=(xx<<(__int64))+bb[i]%;
}
//printf("\n%I64d\n",xx);//(double)
int abs=sqrt((*xx-(__int64)x*x))+eps;//不加(__int64),会WA
printf("%d %d\n",(x-abs)/,(x+abs)/);
}
return ;
}

hdu 3972 1 M possible的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. ECMAScript整理笔记(持续更新....)

    参考文献: ECMAScript Array:http://www.jimmycuadra.com/posts/ecmascript-5-array-methods ECMAScript5兼容展示大全 ...

  2. Mysql 的MYISAM引擎拷贝出现异常——Incorrect information in file 'xxx.frm'

    MYISAM引擎有三个文件 .FRM    存储表结构 .MYD    存储数据 .MYI   存储索引 当复制表时,将这三个文件同时复制到指定目录下. 异常处理: 1. Incorrect info ...

  3. Mysql 正则获取字段的交集【转】

    问题描述 比如table1中有两条记录 name no a    2,9 b    8,10 然后有一串字符串,是0,1,2,3,4 然后通过一条sql,找出no为2,9的记录来``` 因为字符串中有 ...

  4. apk反编译之二——smali学习

    在apk被反编译后,原来的java程序会以smali文件呈现.这就需要补充smali的知识.依旧参考官方文档,择日我将把官方文档做一下翻译.今日先贴出链接地址: 1:了解smali字节码的寄存器 请参 ...

  5. roscpp源码阅读

    roscpp doxgen 这只是我摘取的一些主要代码 node_handle.cpp //NodeHandle的构造函数 void NodeHandle::construct(const std:: ...

  6. JS类库函数收集中....

    实现string的substring方法 方法一:用charAt取出截取部分 String.prototype.mysubstring=function(beginIndex,endIndex){ v ...

  7. MVC的小知识点

    1.MVC的前台页面编译完之后,也会生成一个前台页面类.在前天页面中加入这段代码this.GetType().Assembly.GetLocation()得到当前类所在的程序集,可以查看其所在的程序, ...

  8. Java线程同步(synchronized)——卖票问题

    卖票问题通常被用来举例说明线程同步问题,在Java中,采用关键字synchronized关键字来解决线程同步的问题. Java任意类型的对象都有一个标志位,该标志位具有0,1两种状态,其开始状态为1, ...

  9. 【BZOJ 2245】[SDOI2011]工作安排

    Description 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被编号为1~m员工能够制造的产品种类有所区别.一件产 ...

  10. Jquery datatables 重载数据方法

    参考这里 { RefreshTable('#table-example', '/BlogManage/GetLabelData'); } function RefreshTable(tableId, ...