当前位置:网站首页>Enumeration, simulation, and sorting
Enumeration, simulation, and sorting
2022-07-07 23:39:00 【Yuesi】
acwing Question no 1210
Topic link
Answer link :
1∼N
Section [L,R] All the elements in ( That's the number L One to the first R Elements )
( If the interval [L,R] All the elements in
( That is The first L One to the first R Elements ) You can get a length of R−L+1 Of “ continuity ” The sequence , It's called the serial interval .
PS:
1-n All numbers are in the sequence represented by intervals
The difference between the minimum value and the maximum value after arrangement is equal to the digit difference R-L; namely [L,R] In the interval max-min=R-L;
Be careful :
1. When R And L stay [1,n] Interval time L=R It is also in line with the meaning of the question ;
2. The initial value should be restored every time the maximum and minimum values of the interval are calculated ,
Otherwise, the second comparison will be affected
With two for Interval to traverse all possible interval situations ;
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;//n The scope is [1,10000]
scanf("%d",&n);
int ans[10010];
for(int i=1;i<=n;i++){
scanf("%d",&ans[i]);
}
int cou=0;
for(int i=1;i<=n;i++){
int MIN=1000500,MAX=-1000000;
// Every time we find the minimum and maximum value of the interval, we need Prepare for the second application
for(int h=i;h<=n;h++){
MIN=min(MIN,ans[h]);
MAX=max(MAX,ans[h]);
if(MAX-MIN==h-i){
cou++;
}
}
}
printf("%d\n",cou);
return 0;
}
1236. Increment triples
Topic link :
Answer link :
int pos1=`lower_bound(num,num+6,7)-num`;
// Returns the first... In the array ` Greater than or equal to ` The value of the checked number
int pos2=`upper_bound(num,num+6,7)-num`;
// Returns the first... In the array ` Greater than ` The value of the checked number
Violence solution
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d",&n);
int an[100010],bn[100010],cn[100010];
for(int i=0;i<n;i++){
scanf("%d",&an[i]);
}
for(int i=0;i<n;i++){
scanf("%d",&bn[i]);
}
for(int i=0;i<n;i++){
scanf("%d",&cn[i]);
}
sort(an,an+n);
sort(bn,bn+n);
sort(cn,cn+n);
long long int a=0,c=0;
long long int sum=0;
for(int i=0;i<n;i++){
a=0;
c=0;
while(a<n&&an[a]<bn[i]){
a++;
}
while(c<n&&cn[c]<=bn[i]){
c++;
}
sum+=a*(n-c);
}
printf("%d\n",sum);
return 0;
}
Violent solution data arrives 100000 No result at all
Big brother
Increment triples
边栏推荐
- [summary] some panels and videos seen
- Three questions TDM
- webflux - webclient Connect reset by peer Error
- 高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
- Anxinco esp32-a1s development board is adapted to Baidu dueros routine to realize online voice function
- 【7.5】15. Sum of three numbers
- Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
- Lm12 rolling heikin Ashi double K-line filter
- Summary of common methods of object class (September 14, 2020)
- V-for traversal object
猜你喜欢
Explain
Deep understanding of MySQL lock and transaction isolation level
2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
C inheritance and interface design polymorphism
Interface
【实验分享】通过Console口登录到Cisco设备
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
Svn relocation
Idea automatically generates serialVersionUID
随机推荐
SAP HR reward and punishment information export
USB (XVIII) 2022-04-17
The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
Dependency injection
SLAM面试总结
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
HDU 4747 mex "recommended collection"
Right click the idea file to create new. There is no solution to create new servlet
B_ QuRT_ User_ Guide(40)
Force deduction solution summary 648 word replacement
How to login and enable synchronization function in Google browser
ESP at installation esp8266 and esp32 versions
Idea automatically generates serialVersionUID
数据库面试题+解析
One of the anti climbing methods
MySQL架构
伸展树(一) - 图文解析与C语言实现
The for loop realizes 1-100 addition and eliminates the 4-digit tail number
Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process