当前位置:网站首页>谎牛计数(春季每日一题 53)
谎牛计数(春季每日一题 53)
2022-07-07 14:28:00 【sweetheart7-7】
奶牛 Bessie 躲在数轴上的某处。
农夫约翰的 N N N 头奶牛中的每头奶牛都有一条信息要分享:第 i i i 头奶牛说 Bessie 躲在小于或等于 p i p_i pi 的某个位置,或者说 Bessie 躲在大于或等于 p i p_i pi 的某个位置。
不幸的是,可能不存在躲藏位置与所有奶牛的回答均一致,这意味着并非所有奶牛都在说真话。
计算在撒谎的奶牛的最小数量。
输入格式
输入的第一行包含 N N N。
以下 N N N 行每行包含字符 L 或 G,之后是一个整数 p i p_i pi。L 表示第 i i i 头奶牛说 Bessie 的躲藏位置小于或等于 p i p_i pi,而 G 表示第 i i i 头奶牛说 Bessie 的躲藏位置大于或等于 p i p_i pi。
输出格式
输出在撒谎的奶牛的最小数量。
数据范围
1 ≤ N ≤ 1000 1≤N≤1000 1≤N≤1000,
0 ≤ p i ≤ 1 0 9 0≤pi≤10^9 0≤pi≤109。
输入样例1:
2
G 3
L 5
输出样例1:
0
样例1解释
有可能没有奶牛在撒谎。
输入样例2:
2
G 3
L 2
输出样例2:
1
样例2解释
至少一头奶牛在撒谎。
// 枚举每一个端点,撒谎的牛的数量等于左边的 L 之和 + 右边的 G 之和
// Bessie 所在位置取端点中间和取端点对答案的影响是一样的
#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;
}
边栏推荐
- JS中null NaN undefined这三个值有什么区别
- Personal notes of graphics (3)
- The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
- Horizontal and vertical centering method and compatibility
- Iptables only allows the specified IP address to access the specified port
- AutoLISP series (3): function function 3
- Geoserver2.18 series (5): connect to SQLSERVER database
- Asyncio concept and usage
- 【C 语言】 题集 of Ⅹ
- 121. The best time to buy and sell stocks
猜你喜欢

全网“追杀”钟薛高

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

平衡二叉树(AVL)
![[C language] question set of X](/img/17/bfa57de183c44cf0a3c6637bb65a9d.jpg)
[C language] question set of X

Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation

Description of vs common shortcut keys

【C 语言】 题集 of Ⅹ

Shandong old age Expo, 2022 China smart elderly care exhibition, smart elderly care and aging technology exhibition

如何快速检查钢网开口面积比是否符合 IPC7525

Logback日志框架第三方jar包 免费获取
随机推荐
记一次项目的迁移过程
null == undefined
spark调优(三):持久化减少二次查询
JS modularization
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
Sysom case analysis: where is the missing memory| Dragon lizard Technology
How to implement backspace in shell
The difference and working principle between compiler and interpreter
Binary search tree (basic operation)
Introduction and use of gateway
laravel中将session由文件保存改为数据库保存
平衡二叉树(AVL)
HAVE FUN | “飞船计划”活动最新进展
IP地址和物理地址有什么区别
Vs2019 configuration matrix library eigen
【DesignMode】享元模式(Flyweight Pattern)
Laravel5.1 Routing - routing packets
[Android -- data storage] use SQLite to store data
Build an all in one application development platform, light flow, and establish a code free industry benchmark
Introduction to ThinkPHP URL routing