当前位置:网站首页>Round 1C 2022 - Code jam 2022 b.square (Mathematics, thinking)
Round 1C 2022 - Code jam 2022 b.square (Mathematics, thinking)
2022-07-28 17:10:00 【Code92007】
subject
T(T<=100) Group example , Every time given n(n<=1000) Number , The first i Number ei(-1000<=ei<=1000),
You need to add up to k individual [-1e18,1e18] Range of integers ,
Make this n+k The sum of squares of numbers is equal to the square of sum , namely 
If by no means equal , Output IMPOSSIBLE
Small scale :k=1
large-scale :k<=1000
Source of ideas
Official explanation
Answer key
consider k=1 What to do when , Set the number to be added as x, Shift out x Value ,
,
That is to say
by n The number and ,
by n Sum of squares of numbers ,

stay k>1 when , The denominator 2*sum Inspire us , Try to make new and
by 1,
You need to fill one first
Value ,
Corresponding new sum of squares 
That is to say
,
be aware
It's odd , Show the current n+1 There are odd numbers among them ,
Then the sum of squares must also be odd , namely
Must be an even number ,
Must be an integer
This shows that ,k>1 There must be a solution , And add two numbers
、
that will do
Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+10;
int t,n,k;
ll a[N];
int main(){
scanf("%d",&t);
for(int ca=1;ca<=t;++ca){
scanf("%d%d",&n,&k);
ll sum=0,sum2=0,ans;
printf("Case #%d: ",ca);
for(int i=1;i<=n;++i){
scanf("%lld",&a[i]);
sum+=a[i];sum2+=a[i]*a[i];
}
if(k>=2){
sum2+=1ll*(1-sum)*(1-sum);
printf("%lld ",1-sum);
sum=1;
}
if(!sum){
if(sum*sum==sum2){
puts("0");
}
else{
puts("IMPOSSIBLE");
}
continue;
}
if((sum2-sum*sum)%(2ll*sum)){
puts("IMPOSSIBLE");
}
else{
ans=(sum2-sum*sum)/(2ll*sum);
printf("%lld\n",ans);
}
}
return 0;
}
边栏推荐
- [deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)
- Unity shader procedural texture
- 充分利用----英文
- 做题笔记2(两数相加)
- 技术分享 | 误删表以及表中数据,该如何恢复?
- Re14:读论文 ILLSI Interpretable Low-Resource Legal Decision Making
- Unity shader realizes water wave effect with noise texture
- [deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation
- 阿里云-武林头条-建站小能手争霸赛
- Outline and principle of structured design -- modularization
猜你喜欢

Ruoyi's solution to error reporting after integrating flyway

Using MVC in the UI of unity
![[deep learning]: day 9 of pytorch introduction to project practice: dropout implementation (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 9 of pytorch introduction to project practice: dropout implementation (including source code)

RE14: reading paper illsi interpretable low resource legal decision making
Read excel xlsx format file in unity

在AD中添加差分对及连线

HTAP是有代价的

Microsoft: edge browser has built-in disk cache compression technology, which can save space and not reduce system performance

Alibaba cloud MSE supports go language traffic protection

【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)
随机推荐
Efficiency comparison of three methods for obtaining timestamp
Jsonarray traversal
Time complexity
leetcode70假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
Record the processing process of CEPH two RBDS that cannot be deleted
Epoll horizontal departure, which edge triggers
【深度学习】:《PyTorch入门到项目实战》:简洁代码实现线性神经网络(附代码)
阿里云-武林头条-建站小能手争霸赛
Games101 section 13 ray tracing notes
Re12:读论文 Se3 Semantic Self-segmentation for Abstractive Summarization of Long Legal Documents in Low
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)
Ruoyi集成flyway后启动报错的解决方法
Ugui learning notes (II) Scrollview related
SUSE Storage6 环境搭建详细步骤 – Win10 + VMware WorkStation
Some notes on how unity objects move
Hikvision responded to the impact of the 'US ban': there are options for the components currently used
13 differences between MySQL and Oracle
Outline and principle of structured design -- modularization
Re11: read EPM legal judgment prediction via event extraction with constraints