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 ...
随机推荐
- javascript里面技巧整理
web develop tools secrets: http://jinlong.github.io/blog/2013/08/29/devtoolsecrets/ 1.Date new Date( ...
- Java内存溢出详解
转自:http://elf8848.iteye.com/blog/378805 一.常见的Java内存溢出有以下三种: 1. java.lang.OutOfMemoryError: Java heap ...
- DataGridview动态添加列
1.获取数据源(select * from table名称) 2.动态绑定数据源 private void GetTableInfo(DataTable dt) { listBh = new List ...
- .NET SDK和下载
http://blogs.msdn.com/b/dotnet/p/dotnet_sdks.aspx .NET SDK和下载 您可以通过下载.NET框架针对包和软件开发工具包,并使用它们与Visual ...
- SQL Server 2012 BI 学习 第一天
了解数据源,数据源视图,多维数据集,维度 数据源:一个数据库或者其它数据链接,SSAS不支持使用模拟功能来处理 OLAP 对象.模拟信息选择“使用服务帐户” 数据源视图:DSV是元数据的单个统一视图, ...
- Hive表分区
必须在表定义时创建partition a.单分区建表语句:create table day_table (id int, content string) partitioned by (dt stri ...
- iTween基础之Scale(缩放大小)
一.基础介绍:二.基础属性 原文地址:http://blog.csdn.net/dingkun520wy/article/details/50684392 一.基础介绍 ScaleTo:改变游戏对象的 ...
- 服务器端spice配置详解
1. 安装必要的工具 sudo apt-get install build-essential autoconf git-core intltool 2. 安装必要的依赖包 -dev libxfixe ...
- android聊天,存储聊天记录sqlite
项目中有聊天模块,需要用到打开activity的时候初始化聊天记录的情况.大致情况如下: 辅助类:ChatSQLiteHelper 在第一次时会调用oncreate方法(判断的标准是schedul ...
- android 开发,多个线程共用一个handler
在做项目过程中,突然发现,项目中启动了多个线程,但是只有一个handler,而不需要每一个线程单独开一个handler,记下笔记: handler = new Handler() { @Overrid ...