当前位置:网站首页>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
边栏推荐
- 基于JEECG-BOOT的list页面的地址栏参数传递
- Digital triangle model acwing 1015 Picking flowers
- Manhattan distance sum - print diamond
- [C language] string left rotation
- Left matching principle of joint index
- 黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
- Pat (Grade B) 2022 summer exam
- Past and present lives of QR code and sorting out six test points
- 對數據安全的思考(轉載)
- Customize the gateway filter factory on the specified route
猜你喜欢
![[API interface tool] Introduction to postman interface](/img/03/c1541fca65dd726fd4bdc8793b605e.png)
[API interface tool] Introduction to postman interface

LeetCode 729. 我的日程安排表 I

二维码的前世今生 与 六大测试点梳理

Manhattan distance and Manhattan rectangle - print back font matrix

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

Manhattan distance sum - print diamond
![[postman] the monitors monitoring API can run periodically](/img/9e/3f6150290b868fc1160b6b01d0857e.png)
[postman] the monitors monitoring API can run periodically
![[wechat applet] build a development tool environment](/img/f6/51f97b1c927337b34c5b3a4207abb4.png)
[wechat applet] build a development tool environment

G - Supermarket

浅谈专项测试之弱网络测试
随机推荐
浅谈专项测试之弱网络测试
[postman] collections configuration running process
Simulation volume leetcode [general] 1109 Flight reservation statistics
Testing of web interface elements
Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
Career advancement Guide: recommended books for people in big factories
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
F - true liars (category and search set +dp)
使用Nacos管理配置
LeetCode 731. 我的日程安排表 II
Simulation volume leetcode [general] 1249 Remove invalid parentheses
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
[C language] string left rotation
Simulation volume leetcode [general] 1062 Longest repeating substring
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
模拟卷Leetcode【普通】1405. 最长快乐字符串
数据库隔离级别
10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
An article was uncovered to test the truth of outsourcing companies
G - Supermarket