当前位置:网站首页>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;
}
边栏推荐
- 【Android -- 数据存储】使用 SQLite 存储数据
- JS modularization
- Introduction to ThinkPHP URL routing
- Set the route and optimize the URL in thinkphp3.2.3
- Laravel5.1 Routing - routing packets
- Description of vs common shortcut keys
- 如何快速检查钢网开口面积比是否符合 IPC7525
- Imitate the choice of enterprise wechat conference room
- What else can an ordinary person do besides working in a factory to make money?
- 95. (cesium chapter) cesium dynamic monomer-3d building (building)
猜你喜欢

Description of vs common shortcut keys

The difference and working principle between compiler and interpreter

95. (cesium chapter) cesium dynamic monomer-3d building (building)

Three. JS series (2): API structure diagram-2

Talk about the cloud deployment of local projects created by SAP IRPA studio

Opencv personal notes

删除 console 语句引发的惨案

Introduction and use of gateway

AutoLISP series (1): function function 1

Personal notes of graphics (2)
随机推荐
【Vulnhub靶场】THALES:1
PHP realizes wechat applet face recognition and face brushing login function
torch. Numel action
Iptables only allows the specified IP address to access the specified port
JS modularization
Common training data set formats for target tracking
【DesignMode】外观模式 (facade patterns)
AutoLISP series (3): function function 3
Description of vs common shortcut keys
three.js打造酷炫下雪效果
laravel中将session由文件保存改为数据库保存
模拟Servlet的本质
作为Android开发程序员,android高级面试
thinkphp3.2.3中设置路由,优化url
01tire+ chain forward star +dfs+ greedy exercise one
Laravel changed the session from file saving to database saving
【HCSD大咖直播】亲授大厂面试秘诀-简要笔记
null == undefined
水平垂直居中 方法 和兼容
PHP has its own filtering and escape functions