当前位置:网站首页>P2141 [noip2014 popularization group] abacus mental arithmetic test
P2141 [noip2014 popularization group] abacus mental arithmetic test
2022-07-07 23:40:00 【Yuesi】
P2141 -NOIP2014- Universal group abacus mental arithmetic test
subject
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 .
( This topic is 2014 NOIP Universal T1)
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 .
sample input
4
1 2 3 4
sample output
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 .
【 Data description 】
about 100% The data of ,3 ≤ n ≤ 100, The size of the positive integer given by the test question does not exceed 10,000.
difficulty :
Data elements cannot be duplicated
PS: At first glance, the solution only thinks of adding two elements, which cannot be repeated
( Actually, I don't consider , The values of different elements may be the same , Just consider that the added elements do not represent the same variables )
The main card of this question is not only to match when counting a+b=c Of c Just count the number of , Also need to consider c Whether it has been included .
#include<bits/stdc++.h>
// It's best to write it. #include<iostream>
using namespace std;
int main(){
int a;
int ans[105],num[20005]={
0};
scanf("%d",&a);// Total number of read data
for(int i=0;i<a;i++){
scanf("%d",&ans[i]);// The value of the data
num[ans[i]]=1;// The record data exists in the array
}
int sum=0;
for(int i=0;i<a;i++){
for(int j=i+1;j<a;j++){
//j from i The last one starts , It ensures that every bit is traversed , It will not repeatedly select the two numbers added
if(num[ans[i]+ans[j]]==1){
// Judge whether their sum exists
sum++;
num[ans[i]+ans[j]]=10;// The tag has been tried
}
}
}
printf("%d\n",sum);
return 0;
}
边栏推荐
- 【路径规划】使用垂距限值法与贝塞尔优化A星路径
- Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
- Understand TCP's three handshakes and four waves with love
- SAP HR奖罚信息导出
- Map operation execution process
- C语言学习
- 【7.4】25. K 个一组翻转链表
- 648. Word replacement
- Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
- The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
猜你喜欢
SAP HR reward and punishment information export
【实验分享】通过Console口登录到Cisco设备
What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method
Ora-02437 failed to verify the primary key violation
ESP at installation esp8266 and esp32 versions
C # exchange number, judge to pass the exam
MongoDB快速入门
Markdown
SAP HR 劳动合同信息 0016
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
随机推荐
May day C - most
Anxinco esp32-a1s development board is adapted to Baidu dueros routine to realize online voice function
ASP. Net query implementation
USB (XIV) 2022-04-12
生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行
Summary of SQL single table query 2020.7.27
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
SAP HR labor contract information 0016
ASP. Net open web page
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
Get started with mongodb
B_ QuRT_ User_ Guide(38)
数据分析系列 之3σ规则/依据拉依达准则来剔除异常值
B_QuRT_User_Guide(37)
How to change the formula picture in the paper directly into the formula in word
FPGA basics catalog
保证接口数据安全的10种方案
SAP HR奖罚信息导出
SAP 内存参数调优过程