当前位置:网站首页>Counting Liars
Counting Liars
2022-07-18 06:33:00 【愚者的黄昏】
思路:
将G和L分别存入一个数组,排序后任选其中一个数组进行循环,假设a[i]以前的所有数据均为非法,a[i]以后的数据均为合法,记录数据。再对另一数组操作,所有与a[i]相违背的都是非法(因为数组有序,所以有分界线a[i]>=b[i]),所以对于i位置来说违法数据个数即为i-1+y-j,对i遍历求min即为答案
题干:
奶牛 Bessie 躲在数轴上的某处。
农夫约翰的 N 头奶牛中的每头奶牛都有一条信息要分享:第 i 头奶牛说 Bessie 躲在小于或等于 pi 的某个位置,或者说 Bessie 躲在大于或等于 pi 的某个位置。
不幸的是,可能不存在躲藏位置与所有奶牛的回答均一致,这意味着并非所有奶牛都在说真话。
计算在撒谎的奶牛的最小数量。
输入格式
输入的第一行包含 N。
以下 N 行每行包含字符 L 或 G,之后是一个整数 pi。L 表示第 i 头奶牛说 Bessie 的躲藏位置小于或等于 pi,而 G 表示第 i 头奶牛说 Bessie 的躲藏位置大于或等于 pi。
输出格式
输出在撒谎的奶牛的最小数量。
数据范围
1≤N≤1000,
0≤pi≤109。
输入样例1:
2 G 3 L 5
输出样例1:
0
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=1010,M=0x3f3f3f3f;
typedef long long LL;
int n,t,x,y,a[N],b[N],ans;
char c;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("\n%c%d",&c,&t);
if(c=='L') a[++x]=t;
else b[++y]=t;
}
sort(a+1,a+x+1);
sort(b+1,b+y+1);
ans=n-1;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
if(a[i]>=b[j]) ans=min(ans,i-1+y-j);
else break;
}
}
printf("%d\n",ans);
return 0;
}
边栏推荐
- leach协议性能对比仿真,包括死亡节点数,数据传输,网络能量消耗,簇头产生数以及负载均衡度
- 60种特征工程操作:使用自定义聚合函数
- Juice shop safety test
- Shrimp Shope get commodity list API return value description according to keywords
- ArrayList in collection
- Explore how to leverage the Web3.0 era with storage as the fulcrum
- 我,开了五年快递站,现在还没回本
- Li Hongyi machine learning 2022.07.17 -- Introduction to deep learning and back propagation
- 【C】文件操作
- 三层交换机和单臂路由
猜你喜欢
【PCB开源分享】STC8A8K64D4开发板
Li Hongyi machine learning 2022.07.17 -- Introduction to deep learning and back propagation
C language --- file operation
Solidity中的内联汇编
OSPF综合实验
ShuffleNet 系列(2): ShuffleNet v2 理论讲解
运用滤波反投影的方法对图像进行重建matlab仿真
NFT application "Rhapsody": reviewing the development of NFT market, what changes will there be in the future?
Shufflenet series (1): explanation of shufflenet V1 theory
Cadence learning path: what is the positive and negative of PCB process
随机推荐
[csp-j2019] souvenirs (full backpack, stock trading)
Talking about unit testing: the use of testing and automation
C # XML basic operation 1- create XML files in the current directory
unet 笔记
Load properties file
笔试强训第17天
01.机器学习的简介
【愚公系列】2022年7月 Go教学课程 012-强制类型转换
【C】文件操作
消失之物 O(v) 删除某件物品
OSPF comprehensive experiment
Unity Editor 复制内容到剪切板
Pointer written test questions
Install dart environment and dart related plug-ins in vscode
ShuffleNet 系列(2): ShuffleNet v2 理论讲解
Deep understanding of C pointer 6.4.4 support tree with pointer
TypeScript(tsconfig.json)
集合中的ArrayList
如何写一个自定义注解
解决Microsoft 365和Visio冲突问题