hdu 3972 1 M possible
一般做法:
显然的超内存
#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的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- c#配置log4net步骤
1.引入添加log4net.dll引用 2.建立配置文件Log4Net.config(名字自定义).文件内容参考,输出的文件名称可更改 .运行是要放入到相应bin/debug(release) 目录 ...
- PHP弱类型安全问题笔记
一.类型转换问题 intval(); var_dump(intval('1asdfasd')); //1 var_dump(intval('awqw12')); //0 var_dump(i ...
- 解析php开发中的中文编码问题
其实php开发中的中文编码并没有想像的那么复杂,虽然定位和解决问题没有定规,各种运行环境也各不尽然,但后面的原理是一样的. 了解字符集的知识是解决字符问题的基础. PHP程序设计中中文编码问题曾经困扰 ...
- 冒泡排序(Bubble Sort)
常见的排序算法有Bubble Sort.Merge Sort.Quick Sort 等,所有排序算的基本法思想都是把一个无限大的数据规模通过算法一步步缩小,指导最后完成排序. 这里分享一下Buuble ...
- this.IsMounted() is not a function
I'm trying to build a simple React App. It retrieves data from an ajax call and renders it to the pa ...
- 加载页面遮挡耗时操作任务页面--第三方开源--AndroidProgressLayout
在Android的开发中,往往有这种需求,比如一个耗时的操作,联网获取网络图片.内容,数据库耗时读写等等,在此耗时操作过程中,开发者也许不希望用户再进行其他操作(其他操作可能会引起逻辑混乱),而此时需 ...
- SQL Server 本地语言版本
要一些实验是往往喜欢使用英文的Windows 以及SQL Server ,但有时需要使用中文的环境方便理解.中文的SQL Server 不能被安装在英文的Windows 系统上. 根据文档可得知以下兼 ...
- java的JVM机制
1.jre:java运行环境 提供一个JVM和一些基础类库.2.只安装jre以后,机器就具备了运行java程序的条件.但是不具备开发java程序的条件.安装JDK以后,在c:/program file ...
- iOS JSON解析
解析json成dic对象 -(void)fetchedData:(NSData*)responseData {//parse out the json dataNSError* error; NSDi ...
- MVC C# 调用存储过程
SqlParameter[] param ={ new SqlParameter("@SignInfoId ",SqlDbType.Int), new SqlParameter(& ...