当前位置:网站首页>Lie cow count (spring daily question 53)
Lie cow count (spring daily question 53)
2022-07-07 16:40:00 【sweetheart7-7】
cow Bessie Hiding somewhere on the number axis .
Farmer John's N N N Each of the cows has a message to share : The first i i i Said the cow Bessie Hide below or equal to p i p_i pi A location of , Or say Bessie Hide at greater than or equal to p i p_i pi A location of .
Unfortunately , There may be no hiding place, which is consistent with the answers of all cows , This means that not all cows are telling the truth .
Calculate the minimum number of cows lying .
Input format
The first line of input contains N N N.
following N N N Lines each line contains characters L
or G
, This is followed by an integer p i p_i pi.L
It means the first one i i i Said the cow Bessie The hiding position of is less than or equal to p i p_i pi, and G
It means the first one i i i Said the cow Bessie The hiding position of is greater than or equal to p i p_i pi.
Output format
Output the minimum number of cows lying .
Data range
1 ≤ N ≤ 1000 1≤N≤1000 1≤N≤1000,
0 ≤ p i ≤ 1 0 9 0≤pi≤10^9 0≤pi≤109.
sample input 1:
2
G 3
L 5
sample output 1:
0
Examples 1 explain
It's possible that no cow is lying .
sample input 2:
2
G 3
L 2
sample output 2:
1
Examples 2 explain
At least one cow is lying .
// Enumerate each endpoint , The number of lying cows is equal to that on the left L The sum of the + Dexter G The sum of the
// Bessie The influence of the middle of the endpoint and the endpoint on the answer is the same
#include<iostream>
#include<algorithm>
#define x first
#define y second
using namespace std;
const int N = 1010;
int n;
pair<int, char> q[N];
int s[N];
int main(){
cin >> n;
for(int i = 1; i <= n; i++) cin >> q[i].y >> q[i].x;
sort(q + 1, q + 1 + n);
for(int i = 1; i <= n; i++){
s[i] = s[i - 1];
if(q[i].y == 'L') s[i]++;
}
int res = n;
for(int i = n, r = 0; i; i--){
int j = i, t = 0;
while(j && q[j].x == q[i].x){
if(q[j].y == 'G') t++;
j--;
}
res = min(res, s[j] + r);
r += t;
i = j + 1;
}
cout << res << endl;
return 0;
}
边栏推荐
- 面试题 01.02. 判定是否互为字符重排-辅助数组算法
- Laravel constructor and middleware execution order
- 两类更新丢失及解决办法
- 记一次项目的迁移过程
- Three. JS series (1): API structure diagram-1
- spark调优(三):持久化减少二次查询
- Opportunity interview experience summary
- 【DesignMode】代理模式(proxy pattern)
- 47_ Contour lookup in opencv cv:: findcontours()
- 打造All-in-One应用开发平台,轻流树立无代码行业标杆
猜你喜欢
Three. JS series (2): API structure diagram-2
null == undefined
Personal notes of graphics (3)
AutoLISP series (3): function function 3
Imitate the choice of enterprise wechat conference room
Horizontal and vertical centering method and compatibility
【Android -- 数据存储】使用 SQLite 存储数据
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
Logback日志框架第三方jar包 免费获取
Statistical learning method -- perceptron
随机推荐
Geoserver2.18 series (5): connect to SQLSERVER database
Opencv configuration 2019vs
Performance comparison of tidb for PostgreSQL and yugabytedb on sysbench
打造All-in-One应用开发平台,轻流树立无代码行业标杆
Talk about the cloud deployment of local projects created by SAP IRPA studio
As an Android Developer programmer, Android advanced interview
Tragedy caused by deleting the console statement
【DesignMode】外观模式 (facade patterns)
【DesignMode】模板方法模式(Template method pattern)
The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
Horizontal and vertical centering method and compatibility
MySQL中, 如何查询某一天, 某一月, 某一年的数据
Laravel 中config的用法
[medical segmentation] attention Unet
spark调优(三):持久化减少二次查询
How to query the data of a certain day, a certain month, and a certain year in MySQL
[designmode] facade patterns
The difference and working principle between compiler and interpreter
[Android -- data storage] use SQLite to store data