当前位置:网站首页>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
边栏推荐
- New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
- PCB wiring rules of PCI Express interface
- 产业共融新势能,城链科技数字峰会厦门站成功举办
- Have all the fresh students of 2022 found jobs? Is it OK to be we media?
- Design and implementation of spark offline development framework
- Installing gradle
- StringUtils工具类
- MySQL架构
- Sequence of entity layer, Dao layer, service layer and controller layer
- 【leetcode】day1
猜你喜欢
![[compilation principle] lexical analysis design and Implementation](/img/8c/a3a50e6b029c49caf0d791f7d4513a.png)
[compilation principle] lexical analysis design and Implementation

New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
![Arbre binaire équilibré [Arbre AVL] - Insérer et supprimer](/img/1f/cd38b7c6f00f2b3e85d4560181a9d2.png)
Arbre binaire équilibré [Arbre AVL] - Insérer et supprimer

UE4_ Ue5 combined with Logitech handle (F710) use record

移动端异构运算技术 - GPU OpenCL 编程(基础篇)

The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way

SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration

Svn relocation

0-1 knapsack problem

B_QuRT_User_Guide(36)
随机推荐
2022第六季完美童模陕西总决赛圆满落幕
Anxin vb01 offline voice module access intelligent curtain guidance
建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
POJ2392 SpaceElevator [DP]
MySQL Index Optimization Practice II
B / Qurt Utilisateur Guide (36)
Ora-02437 failed to verify the primary key violation
S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
Extended tree (I) - graphic analysis and C language implementation
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
The file format and extension of XLS do not match
C simple question one
ASP. Net query implementation
Come on, brother
B_ QuRT_ User_ Guide(37)
B_QuRT_User_Guide(39)
城联优品作为新力量初注入,相关上市公司股价应声上涨150%
UE4_ Ue5 panoramic camera