当前位置:网站首页>蓝桥杯-四平方和
蓝桥杯-四平方和
2022-07-22 11:07:00 【ai_moe】
题目详情
解题代码
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 2.5e7+10;
struct Sum
{
int s,c,d;
bool operator< (const Sum &t)const
{
if(s!=t.s) return s<t.s;
if(c!=t.c) return c<t.c;
return d<t.d;
}
}sum[N];
int n,m;
int main()
{
cin >> n ;
for(int c=0;c*c<=n;c++)
for(int d=c;c*c+d*d<=n;d++)
sum[m++]={
c*c+d*d,c,d};
sort(sum,sum+m);
for(int a=0;a*a<=n;a++)
for(int b=0;b*b+a*a<=n;b++)
{
int t=n-a*a-b*b;
int l=0,r=m-1;
while(l<r)
{
int mid = l+r>>1;
if(sum[mid].s>=t) r=mid;
else l=mid+1;
}
if (sum[l].s == t)
{
printf("%d %d %d %d\n", a, b, sum[l].c, sum[l].d);
return 0;
}
}
return 0;
}
边栏推荐
猜你喜欢
Buuctf breakthrough diary 02-- [hctf 2018] warmup1
JUC-6.2-并发容器-CopyOnWriteArrayList
Juc-6.3-concurrency container queue
1.虚拟化和容器技术
Learning notes of wechat applet introduction tutorial - operation feedback of UI chapter
Significance learning record of FFT in MATLAB
二分-机器人跳跃问题
Application & rich text editor & file upload
10.系统信息相关命令
Buuctf breakthrough diary -- [geek challenge 2019] hardsql1
随机推荐
Process control
Buuctf entry diary -- [suctf 2019]checkin1()
Juc-6.2-concurrency container copyonwritearraylist
Bash variable -- user defined variable
pytorch, 指定显卡问题
Juc-8.0-future and callable
C# Winform开发 弹出式输入框 文本框
如何做好研发精益需求管理
操场运动场室外扩声系统方案与功能分析
LeetCode笔记(一)回溯
Web编程入门 2.3 解决fakepath问题 获取本地文件真实地址
1. Virtualization and container technology
(6) Vulhub column: apereo CAS 4.x deserialization vulnerability
解决编译mosquitto时遇到的问题
校园IP网络广播案例-石家庄法商中等专业学校鹿泉校区校园IP广播系统应用
[lttng learning journey] - environment construction
[lttng learning journey] ----- components of lttng deconstruction
RPM package management - Yum online management - IP address configuration and network Yum source
链表中的双指针——快慢指针
Blue Bridge Cup - incremental triples