当前位置:网站首页>Niuniu looks at the cloud (greedy, hash, push formula) - the first session of Niuke winter vacation training camp
Niuniu looks at the cloud (greedy, hash, push formula) - the first session of Niuke winter vacation training camp
2022-06-26 07:20:00 【Sss_ xxh、】
Original link
subject

Ideas
- The most important point of this question is to pay attention to the observed data range , It shows that there must be a number of repeated occurrences
- Consider hash , Record the number of occurrences of each number
- For two different numbers , They can form a total of according to the requirements of the topic c n t a ∗ c n t b cnt_a * cnt_b cnta∗cntb Same combination
- For two identical numbers , They can form a total of according to the requirements of the topic ( 1 + c n t a ) ∗ c n t a / 2 (1 + cnt_a) * cnt_a / 2 (1+cnta)∗cnta/2 Same combination 【 Refer to the prime minister's formula with the final term 】.
- Pay attention l o n g l o n g longlong longlong
Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n;
cin >> n;
map<int, int> ma;
for (int i = 1; i <= n; i ++ )
{
int x;
cin >> x;
ma[x] ++;
}
int sum = 0;
for (int i = 0; i <= 1000; i ++ )
{
for (int j = i; j <= 1000; j ++ )
{
int add;
if (i == j) add = (1 + ma[i]) * ma[i] / 2;
else add = ma[i] * ma[j];
sum += abs(i + j - 1000) * add;
}
}
cout << sum << endl;
return 0;
}
summary
During the game, I actually thought about the data range , But then I thought of using set do , In short, it's just another detour , You still need to pay attention to your mentality during the game , Otherwise, you can't do simple problems .
Post a race time error code
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
set<int> s;
unordered_map<int, int> ma;
int n;
cin >> n;
for (int i = 1; i <= n; i ++ )
{
int x;
cin >> x;
ma[x] ++;
s.insert(x);
}
int sum = 0;
for (auto i : s)
{
for (int j : s)
{
if (i == j)
{
sum = sum + abs(i + j - 1000) * (ma[i] * (ma[i] - 1));
}
else
{
sum = sum + abs(i + j - 1000) * (ma[i] * ma[j] );
}
}
}
cout << sum << endl;
return 0;
}
边栏推荐
- Typescript: use polymorphism instead of switch and other conditional statements
- 报错问题Parameter index out of range(0 < 1) (1 > number of parameters,which is 0
- I3wm get window class
- QT basics tutorial: qstring
- Dark red crystal meso-5,10,15,20-tetra (p-aminophenyl) cobalt porphyrin (co TAPP); Meso-5,10,15,20-tetra (p-aminophenyl) cobalt porphyrin no complex (TAPP co no) supplied by Qiyue
- Thymeleaf中使用二维数组[[]]报错:Could not parse as expression
- 卡尔曼滤波器_Recursive Processing
- 面试被问Redis主从复制不会答?这13张图让你彻底弄明白
- $a && $b = $c what???
- $a && $b = $c what???
猜你喜欢

Deep exploration image theme color extraction

Service interface test guide

MySQL basic usage 01

ZRaQnHYDAe

Tetra - (4-pyridyl) porphyrin tpyp and metal complexes zntpyp/fetpyp/mntpyp/cutpyp/nitpyp/cotpyp/ptpyp/pdtpyp/cdtpyp (supplied by Qiyue porphyrin)

Iron / zinc / copper / platinum metal complexes such as 5,10,15,20-tetra (4-hydroxyphenyl) porphyrin (THPP) / (thppfe) / (thppzn) / (thppcu) / (thpppt) - Qiyue R & D

报错问题Parameter index out of range(0 < 1) (1 > number of parameters,which is 0

Stm32f1 and stm32subeide programming example - thermal sensor driver
![5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes](/img/51/136eda75986fc01282558e626b2faf.jpg)
5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes

Porphyrin based polyimide (ppbpis); Synthesis of crosslinked porphyrin based polyimides (ppbpi CRS) porphyrin products supplied by Qiyue biology
随机推荐
Recognize pnpm: faster, higher performance NPM
The performance of iron and steel enterprises was expected to be good in January this year. Since February, the prices of products of iron and steel enterprises have increased significantly. A mighty
Detailed materials of applying for residence permit in non local Beijing
QPS
Procedure macros in rust
QPS
Analyze 5 indicators of NFT project
How to publish function computing (FC) through cloud effect
Six stones Management: exaggerating the achievements, whether the parties themselves know
Kalman filter_ Recursive Processing
Excel中Unicode如何转换为汉字
Liujinhai, chief architect of zhongang Mining: according to the analysis of fluorite supply and demand, it is estimated that the fluorine coating market has great potential
Porphyrin based polyimide ppbpis (ppbpi-pa, ppbpi-pepa and ppbpi-pena); Crosslinked porphyrin based polyimide (ppbpi-pa-cr, ppbpi-pepa-cr, ppbpi-pena-cr) reagent
Cache usage
[cellular automata] Based on cellular automata, realize the traffic flow problem of expressway toll station, with matlab code
5,10,15,20-tetraphenylporphyrin (TPP) and metal complexes fetpp/mntpp/cutpp/zntpp/nitpp/cotpp/pttpp/pdtpp/cdtpp supplied by Qiyue
Oracle creates stored procedures with return values and executes SQL calls
es 中 mapping 简介
Invalid problem of self defined map used by Gaode map
[image segmentation] blood vessel extraction from retinal fundus images based on maximum principal curvature with matlab code