当前位置:网站首页>Luogu p2141 abacus mental arithmetic test
Luogu p2141 abacus mental arithmetic test
2022-07-06 06:24:00 【zjsru_ Beginner】
Title Description
Abacus mental calculation is a kind of calculation technology that can complete fast calculation by simulating the change of abacus in the brain . Abacus mental arithmetic training , Can develop intelligence , It can bring a lot of convenience to our daily life , So it's popularized in many schools .
Some school's abacus mental arithmetic teacher uses a kind of quick examination abacus mental arithmetic addition ability test method . He randomly generates a set of positive integers , The numbers in the set are different , Then ask the students to answer : How many of them , Exactly equal to the other two in the set ( Different ) Sum of the numbers ?
Recently, the teacher gave some test questions , Please help me find out .
Input format
There are two lines , The first line contains an integer n, The number of positive integers given in the test .
The second line has n A positive integer , Every two positive integers are separated by a space , A positive integer given in a test .
Output format
An integer , The answer to a test question .
I/o sample
Input #1 Copy
4 1 2 3 4
Output #1 Copy
2
explain / Tips
【 Sample explanation 】
from 1+2=3,1+3=4, So the answer to meet the test requirements is 2.
Be careful , The addend and the addend must be two different numbers in the set .
Their thinking :
First sort all numbers , Then calculate the sum of each logarithm . Then use binary search to find whether there is this and... In the sorted array , And judge whether it is the first time , If so, count it as one .
The code is as follows :
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[110],b[110];
int find(int x)
{
int low = 1, high = n,mid;
while (low <= high)
{
mid = (low + high) / 2;
if (a[mid] == x)
{
if (b[mid] == 0)
{
b[mid]++;
return 1;
}
else return 0;
}
else if (a[mid] < x) low = mid + 1;
else if (a[mid] > x) high = mid - 1;
}
return 0;
}
int main()
{
int sum = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n-1; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (find(a[i] + a[j])) sum++;
}
}
cout << sum << endl;
return 0;
}zbh
边栏推荐
- Convert the array selected by El tree into an array object
- 联合索引的左匹配原则
- Simulation volume leetcode [general] 1314 Matrix area and
- Full link voltage measurement: building three models
- 記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
- On weak network test of special test
- Understanding of processes and threads
- Database - current read and snapshot read
- Aike AI frontier promotion (2.13)
- [no app push general test plan
猜你喜欢

F - True Liars (种类并查集+DP)

How to extract login cookies when JMeter performs interface testing
![[postman] collections - run the imported data file of the configuration](/img/85/7ac9976fb09c465c88f376b2446517.png)
[postman] collections - run the imported data file of the configuration

联合索引的左匹配原则

B - The Suspects

記一個基於JEECG-BOOT的比較複雜的增删改功能的實現

基于JEECG-BOOT制作“左树右表”交互页面

Construction and integration of Zipkin and sleuth for call chain monitoring

MySQL is sorted alphabetically
![[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development](/img/63/dc729d3f483fd6088cfa7b6fb45ccb.png)
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
随机推荐
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
模拟卷Leetcode【普通】1218. 最长定差子序列
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
E - 食物链
Past and present lives of QR code and sorting out six test points
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
【无App Push 通用测试方案
Testing of web interface elements
一文揭开,测试外包公司的真 相
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
通过修改style设置打印页样式
Summary of the post of "Web Test Engineer"
Pat (Grade B) 2022 summer exam
B - The Suspects
Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
JDBC requset corresponding content and function introduction
测试周期被压缩?教你9个方法去应对
模拟卷Leetcode【普通】1296. 划分数组为连续数字的集合